in reply to Parsing a file

You're reading the file twice
while(<FILE>) { ## assign $_ to readline *FILE my $message = <FILE>; ## assign my $message to readline *FILE
Which is one problem, and another is you're using the regex anchor \A which matches the beginning of a string. So you're matching berta226: to the beginning of the string, which will also make the regex fail. If you change your code to something like this you should get the desired output (updated - dropped extraneous semi-colon on second line. update 2: also fixed a further 2 mistakes as noted below .oO(note to self - don't post in a hurry shortly before leaving ... ))
while(my $message = <FILE>) { print "$1: $2<br/>" if $message =~ /^(Alberta226: )([a-zA-Z, 0-9]+)/; # I added the + }
See. perlsyn and perlre for more info.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Parsing a file
by sulfericacid (Deacon) on Jan 23, 2004 at 07:35 UTC
    I know I'm not the smartest person here or even really all that great with regexes, but shouldn't the + be inside the ()'s like ([a-zA-Z, 0-9]+)? Otherwise it'll only trap the first character in the rexex.


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: Re: Parsing a file
by Anonymous Monk on Jan 22, 2004 at 19:20 UTC
    I tried your snippet but it keeps erroring out on if /^.., do you have any idea why?
      I think the line before the if wasn't supposed to have a semi-colon (;) at the end.
Re: Re: Parsing a file
by Anonymous Monk on Jan 22, 2004 at 20:16 UTC
    This is so weird. I rid of the colon and it doesn't crash, but it doesn't print or find anything. An exact copy of my log file is
    Paltalk: This is a G rated voice group intended for a General Audience + including minors. Offensive language is not permitted. To speak, h +old the ctrl key down. ladymindy: gu ladymindy: jo ladymindy: hi pixelatedcyberdust: hi Alberta226: ((((( LM )))))) ladymindy: ((((((much)))))) ladymindy: i can t read ladymindy: (((((((alkberta)()))))) eartistp: hey pixels awake too eartistp: can't type either today lol pixelatedcyberdust: yep, very awake Alberta226: much is here ???
      If you're using this code:
      while(my $message = <FILE>) { print "$1: $2<br/>" if /^(Alberta226: )([a-zA-Z, 0-9])+/; # I added the + }

      you'll need to fix one little thing. The lines from FILE are being assigned to $message but the regex is matching against $_

      So you could do this as
      while(<FILE>) { print "$1: $2<br/>" if /^(Alberta226: )([a-zA-Z, 0-9])+/; }

      or
      while(my $message = <FILE>) { print "$1: $2<br/>" if $message =~/^(Alberta226: )([a-zA-Z, 0-9])+/; }