perl strings

C

Cristian Zoicas

Hello all

I would like to know more about the perl strings. Is there
any documentation explaining in detail what a perl string
can contain ?

For example, right now I have written the following piece of program
and I would like to know if it is a valid one for reading binary files:


open( INFILE, "f.txt" );

while( <INFILE> )
{
print( ":" . $_ );
}

thx.
cristi
 
R

Reinhard Pagitsch

Hello Cristian,

Cristian said:
Hello all

I would like to know more about the perl strings. Is there
any documentation explaining in detail what a perl string
can contain ?
Yes, perldoc perldata -> look at scalars
"Strings" in perl are scalars.
For example, right now I have written the following piece of program
and I would like to know if it is a valid one for reading binary files:


open( INFILE, "f.txt" );

while( <INFILE> )
{
print( ":" . $_ );
}

Sure you can do it, depends on what you want todo. (Nothing is
impossible with Perl.)

Better is to use binmode(INFILE) to tell Perl it is a binary file.
To print a binary file to the console it is not a good idea, especial
under Windows. It can be that you bother your colleagues with continous
sound from the speaker :)

regards,
Reinhard
 
A

Anno Siegel

Cristian Zoicas said:
Hello all

I would like to know more about the perl strings. Is there
any documentation explaining in detail what a perl string
can contain ?

Anything. Any sequence of bytes can form a Perl string.
For example, right now I have written the following piece of program
and I would like to know if it is a valid one for reading binary files:


open( INFILE, "f.txt" );

while( <INFILE> )
{
print( ":" . $_ );
}

Your code has other problems. On windowish systems, you may need to set
binmode on the filehandle (see perldoc -f binmode). Further, <INFILE>
is a line oriented operation, but binary files don't have lines. They
may happen to contain line-feeds in random places, which will then
randomly determine what each <INFILE> reads. Binary files are read in
fixed chunks using read() (see perldoc -f read).

Anno
 
B

Brian Wakem

Reinhard said:
Sure you can do it, depends on what you want todo. (Nothing is
impossible with Perl.)


If you can write a script to tell me next week's lottery numbers I'd be
grateful. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top