Loading ...
Sorry, an error occurred while loading the content.

Simple split() question

Expand Messages
  • sbasak@iname.com
    Hi, I want to perform a simple split operation, but can t get the regular expr working. Can anybody help me on this? my $line from a file read is: xyz abc 12sd
    Message 1 of 3 , Jun 30, 2001
    • 0 Attachment
      Hi,

      I want to perform a simple split operation, but can't get the regular
      expr working. Can anybody help me on this?

      my $line from a file read is:
      xyz abc 12sd "pqr stz" dfg (delimited by blank char).
      I'm doing
      my ($par1, $par2, $par3, $par4, $par5) = split(/ /, $line);
      and I'm getting
      $par4 = "pqr
      $par5 = stz", which I don't want.

      I want $par4 = "pqr stz", & $par5 = dfg

      Thanks in advance.
      -Basak
    • Franki
      Hi all, I have a script that creates a unique file for each person that use it.. and the file is used to track their progress... for some reason, it works on
      Message 2 of 3 , Jun 30, 2001
      • 0 Attachment
        Hi all,


        I have a script that creates a unique file for each person that use it.. and
        the file is used to track their progress...

        for some reason, it works on Linux/unix servers, but not on the NT/2000 test
        server with IIS5 and activeperl...

        here is the line in question..

        open (CART, "+>>$sc_cart_path") || &file_open_error("$sc_cart_path", "Add to
        Cart", __FILE__, __LINE__);

        now $sc_cart_path is basically the explicit path to the directory, with the
        new unique file name tacked onto the end..

        doesn't +>> mean that open the file and append to it if possible, or if file
        doesn't exist create it??

        it doesn't work though,, I get an error message stating:
        FILE OPEN
        ERROR-Inetpub/Scripts/cgi-bin-2000/scripts/gshop/shopping_carts/8679809.1548
        |FILE=C:\Inetpub\Scripts\cgi-bin-2000\scripts\gshop\gshop.cgi|LINE=637

        even if I manually create the file, the script won't write to it... and
        still reports the error.


        I have many other instances in this script that write to existing files, and
        they do that just fine, but this is the only one that creates a file each
        time it runs..

        the file name is usually something like: 8679809.1548 with is long and
        obtuse to make sure it is unique...


        does anyone know what I am doing wrong ? its driving me nuts.. I have been
        staring at the script for hours to now avail...


        kindest regards

        Frank




        -----Original Message-----
        From: sbasak@... [mailto:sbasak@...]
        Sent: Saturday, 30 June 2001 5:27 PM
        To: perl-beginner@yahoogroups.com
        Subject: [PBML] Simple split() question


        Hi,

        I want to perform a simple split operation, but can't get the regular
        expr working. Can anybody help me on this?

        my $line from a file read is:
        xyz abc 12sd "pqr stz" dfg (delimited by blank char).
        I'm doing
        my ($par1, $par2, $par3, $par4, $par5) = split(/ /, $line);
        and I'm getting
        $par4 = "pqr
        $par5 = stz", which I don't want.

        I want $par4 = "pqr stz", & $par5 = dfg

        Thanks in advance.
        -Basak




        Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      • James E Keenan
        ... my $line from a file read is: xyz abc 12sd pqr stz dfg (delimited by blank char). I m doing my ($par1, $par2, $par3, $par4, $par5) = split(/ /, $line);
        Message 3 of 3 , Jul 1, 2001
        • 0 Attachment
          On Sat, 30 Jun 2001 sbasak@... wrote:
          >>>
          my $line from a file read is:
          xyz abc 12sd "pqr stz" dfg (delimited by blank char).
          I'm doing
          my ($par1, $par2, $par3, $par4, $par5) = split(/ /, $line);
          and I'm getting
          $par4 = "pqr
          $par5 = stz", which I don't want.

          I want $par4 = "pqr stz", & $par5 = dfg
          >>>

          Assuming the character '_' does not occur within a string such as "pqr stz",
          why not substitute '_' for ' ' first, do the split, then switch back to ' '?

          my $line = '';
          my @pars = ();

          $line = 'xyz abc 12sd "pqr stz" dfg kfc non "test test1"';
          $line =~ s|"(\w+) (\w+)"|"$1_$2"|g;

          @pars = split(/ /, $line);
          foreach (@pars) {
          $_ =~ s|"(\w+)_(\w+)"|"$1 $2"|g;
          print "$_\n";
          }

          Jim Keenan
          jkeen@...
          Brooklyn, NY
        Your message has been successfully submitted and would be delivered to recipients shortly.