perl strings

Discussion in 'Perl Misc' started by Cristian Zoicas, Aug 22, 2005.

  1. 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
     
    Cristian Zoicas, Aug 22, 2005
    #1
    1. Advertising

  2. Hello Cristian,

    Cristian Zoicas wrote:
    > 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
     
    Reinhard Pagitsch, Aug 22, 2005
    #2
    1. Advertising

  3. Cristian Zoicas

    Anno Siegel Guest

    Cristian Zoicas <> wrote in comp.lang.perl.misc:
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Aug 22, 2005
    #3
  4. Cristian Zoicas

    Brian Wakem Guest

    Reinhard Pagitsch wrote:

    > 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. :)



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Aug 22, 2005
    #4
  5. Cristian Zoicas

    Guest

    Brian Wakem <> wrote:
    > Reinhard Pagitsch wrote:
    >
    > > 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. :)


    Sure. Am I allowed to use "sleep 604800;" in it?

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Aug 22, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kurt Krueckeberg
    Replies:
    2
    Views:
    717
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Nov 17, 2004
  2. Rick

    Comparing strings from within strings

    Rick, Oct 21, 2003, in forum: C Programming
    Replies:
    3
    Views:
    388
    Irrwahn Grausewitz
    Oct 21, 2003
  3. Klaus Neuner
    Replies:
    7
    Views:
    498
    Klaus Neuner
    Jul 26, 2004
  4. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    768
    Malcolm
    Jun 24, 2006
  5. lucy
    Replies:
    7
    Views:
    186
    Joe Smith
    Sep 3, 2004
Loading...

Share This Page