For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > Re: Opening .dat file in perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Opening .dat file in perl
Paul Lalli

2006-10-30, 7:03 pm

Goksie wrote:
[color=darkred]
> the code is as follow
>
> #!c:/perl/bin/perl
> use warnings ;
> use strict ;
> my $fl = "c:/Perl/CDR_MSC_DAT/00016363.DAT";
> { local ($\) = ("\n") ;
> open my $fh, '<', $fl or die "open '$fl': $!" ;
> while (<$fh> )
> {
> print $fh;
> }
> }
>
> the output is
> perl fdmacdr.pl
> GLOB(0x225218)
> GLOB(0x225218)
> GLOB(0x225218)


This is the one and only downside of using lexical filehandles I've
ever found. You can't use the default that print() prints $_ if not
given an argument. You have to state it explicitly:

while (<$fh> ) {
print $fh $_;
}

Those extra two characters of typing are well worth the benefits,
however.

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com