develooper Front page | perl.beginners | Postings from February 2009

Re: breaking-apart and printing an input file

Thread Previous | Thread Next
From:
pablo
Date:
February 20, 2009 01:23
Subject:
Re: breaking-apart and printing an input file
Message ID:
20090220092345.GB7644@arch
> 
> Your data is perfect for the paragraph mode* of readline:
> 
Ahh, I forgot about paragraph mode.

> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $user  = shift;
> my $regex = qr/\A$user/;
> 
> local $/ = '';
> while (my $record = <DATA>) {
> 	chomp $record;
> 	if ($record =~ /$regex/) {
> 		print "$record\n";
> 		last;

This didn't work at first.  Then I realized it was because the file's
lines were terminated with "\r\n" instead of just "\n".  Removing the
"\r" fixed the problem and it worked.

thanks for the help.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About