foreach does this because of the PERL IFS (Internal Field Seperator) which
is by default to be ' \n\t' (maybe more, can't fully remember).  So the
foreach will split on the IFS, which is space, newline and tab.  You can set
the IFS to be just newline and then the foreach should work as expected.
The PERL docs can tell you what the builtin variable name is for the IFS,
and show you how to change it.

/B
----- Original Message -----
From: "Robert Canary" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 21, 2003 23:11
Subject: Re: [OFFTOPIC]Quick Perl Question


> That is something like what I just did..
>
> &store_header($paragraph);
>
> sub store_header
> {
>  my ($paragraph) [EMAIL PROTECTED];
>  my (@paragraph) = split("\n", $paragraph);
>
>  while (pop @paragraph)
>  {
>    $global_header_list .= if /^dn/
>  }
>
> The hang up a had (other than brain dead after 12 hours) was trying to
> feed through the variable.  A "foreach" locked onto each word, a "while"
> went into an infinet loop.  The pop did the trick....
>
> Thanks
>
>
> gabriel wrote:
> >
> > On March 22, 2003 01:07 am, Robert Canary wrote:
> > > I am trying figure out how do comb through a $variable that has
multiple
> > > "\n" and each line has various number of characters, and white spaces.
> > > A for loop won't work, it keeps capturing individual words, I need to
> > > capture whole lines.
> >
> > i'm having trouble understanding exactly what you're looking for, but
for my
> > best guess, i'd suggest the following:
> >
> > my @lines = split("\n", $paragraph);
> >
> > for (my $i = 0; $i <= scalar(@lines) - 1; $i++) {
> >         echo "$line[$i]\n";
> > }
> >
> > --
> > if we teach our children by example,
> > we only have ourselves to blame for what they become
> >   - unknown
> >
> > --
> > redhat-list mailing list
> > unsubscribe mailto:[EMAIL PROTECTED]
> > https://listman.redhat.com/mailman/listinfo/redhat-list
>
>
>
> --
> redhat-list mailing list
> unsubscribe mailto:[EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-list



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to