On Jun 2, David Gilden said:

>Is one of these preferred over the other?
>
>        while(<FROMFILE>){
>        push(@everyline, $_);
>     }
>
>$longstring = join("",@everyline);
>@oldentries = split(/<!--NEWENTRY-->/,$longstring);

It's kinda silly to make an array, just to join the elements together
later.  Use a string.

>open(FROMFILE,$filename);
>
>    while (<FROMFILE>){
>   $longstring .=  $_;
>}
>
>@entries = split ('<!--NEWENTRY-->', $longstring);

Even better, you can slurp the ENTIRE file into a string all at once:

  { local $/;  $entire_file = <FILE>; }

>@entries = split (/<!--NEWENTRY-->/, $longstring);

The first argument to split() *is* a regex, and NOT just a string.  You
should use the /.../ notation whenever possible (unless you're doing the
magical split on ' ').

But here's an even cooler solution to your problem.

  # define a "record" as that which ends in "<!--NEWENTRY-->"
  $/ = "<!--NEWENTRY-->";

  while (<FILE>) {
    chomp;  # remove "<!--NEWENTRY-->" from the end
    # deal with $_ as you wish
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to