in reply to problem with array

There are a stack of things that look odd in your code with the top of the list being if(<end/>){. However, the following solution to your problem as expressed may help:

use strict; use warnings; my $str = <<DATA; <ref id="ref1"> <ref id="ref2"> <ref id="ref3"> </end> <ref id="ref4"> <ref id="ref5"> </end> <ref id="ref6"> <ref id="ref7"> <ref id="ref8"> </end> DATA open IN, '<', \$str || die "\nCan't open test.in\n $!\n"; local $/ = '</end>'; while (<IN>) { my @avalues = /="([^"]+)"/g; next unless @avalues; print "New Group: @avalues\n"; } close (IN);

Prints:

New Group: ref1 ref2 ref3 New Group: ref4 ref5 New Group: ref6 ref7 ref8

Note the \$str trick is just to avoid requiring a file external to the sample code.


Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^2: problem with array
by johngg (Canon) on Aug 20, 2008 at 10:16 UTC
    Note the \$str trick is just to avoid requiring a file external to the sample code.

    I tend to open the filehandle directly on a reference to the heredoc to avoid using a variable. You may consider that is going too far :-)

    open my $inFH, q{<}, \ << 'EOD' or die qq{open: << heredoc: $!\n}; .... .... EOD

    If the filehandle was to be opened in some inner scope I would use a variable as you have done to avoid the heredoc messing up indentation.

    Cheers,

    JohnGG

Re^2: problem with array
by texuser74 (Monk) on Aug 20, 2008 at 04:35 UTC
    Hi, Thanks for your answers. now its working fine.