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
Goke Aruna

2006-10-20, 6:56 pm

On 10/20/06, John W. Krahn <krahnj@telus.net> wrote:
>
> Goksie wrote:
>
> open my $fh, '<', '00016367.DAT' or die "Cannot open '00016367.DAT' $!";
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order. -- Larry Wall
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>



thanks John

Each time i used it that way its giving me

GLOB(0x22519c)

thanks

goksie

John W. Krahn

2006-10-20, 6:56 pm

Goke Aruna wrote:
> On 10/20/06, John W. Krahn <krahnj@telus.net> wrote:
>
> Each time i used it that way its giving me
>
> GLOB(0x22519c)


Then you are probably doing something wrong although it is hard to tell as you
haven't shown us any code.



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Tommy Nordgren

2006-10-21, 6:57 pm


On 20 okt 2006, at 21.31, Goke Aruna wrote:

> On 10/20/06, John W. Krahn <krahnj@telus.net> wrote:
>
> thanks John
>
> Each time i used it that way its giving me
>
> GLOB(0x22519c)
>


This might occur because you are trying to print the file handle
instead of reading FROM it.

> thanks
>
> goksie


------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.nordgren@chello.se


Goksie

2006-10-24, 7:57 am

Tommy Nordgren wrote:
>
> On 20 okt 2006, at 21.31, Goke Aruna wrote:
>
>
> This might occur because you are trying to print the file handle
> instead of reading FROM it.
>
> Thank you,


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)
its not a music file... cos another program though proprietary has
opened it.

goksie

> ------------------------------------------------------
> "Home is not where you are born, but where your heart finds peace" -
> Tommy Nordgren, "The dying old crone"
> tommy.nordgren@chello.se
>
>
>
> --To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


John W. Krahn

2006-10-30, 7:03 pm

Goksie wrote:
> Tommy Nordgren wrote:
>
> 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': $!" ;


You are opening the file READONLY (the second argument '<').


> while (<$fh> )


This is fine, you are allowed to read from the $fh filehandle.


> {
> print $fh;


You can't print to the filehandle because it is READONLY. You probably want
to print the contents of the $_ variable:

print $_;


> }
> }
>
> the output is
> perl fdmacdr.pl
> GLOB(0x225218)
> GLOB(0x225218)
> GLOB(0x225218)
> its not a music file... cos another program though proprietary has
> opened it.



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Dr.Ruud

2006-10-31, 3:57 am

Goksie schreef:

> #!perl
> use warnings ;
> use strict ;
> my $fl = "c:/Perl/CDR_MSC_DAT/00016363.DAT";


That is probably not a line-oriented file.

I would change that line to the more robust:
my $fl = q{c:/Perl/CDR_MSC_DAT/00016363.DAT} ;
because filenames can contain sigils etc.

> { local ($\) = ("\n") ;
> open my $fh, '<', $fl or die "open '$fl': $!" ;


You'll probably want to do a binmode-call here.

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


That will print an extra "\n" after each "line", because you set up $\
for that, so the output file will be bigger than the input file.

> }
> }


<quote source="perlvar">
Setting $/ to a reference to an integer, scalar containing an
integer, or scalar that's convertible to an integer will
attempt to read records instead of lines, with the maximum
record size being the referenced integer.
</quote>

See also `perldoc -f read`, specifically LENGTH.

--
Affijn, Ruud

"Gewoon is een tijger."

Sponsored Links







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

Copyright 2008 codecomments.com