in reply to Re^2: Seperating individual lines of a file
in thread Seperating individual lines of a file

First, that's an interesting use of push - you could just do @DATA=<ORIGFILE>;, but I don't think that's a big deal.

Second, you'll find that you'll want to open your file for writing by using the open, FILEHANDLE, ">filename" nomenclature.

Third, as written, your code will open a file called "host1 BUNCHOFDATAINALINE". You might want to split( /pattern/, expression ) each line of the file so you can separately refer to the separate pieces of data, like ( $HOSTNAME, $SOMEDATA ).



--chargrill
$/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } + sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu +" );

Replies are listed 'Best First'.
Re^4: Seperating individual lines of a file
by tgrossner (Novice) on Feb 02, 2006 at 22:24 UTC
    ok, on the split function, can i split $line into two sections, one being the first 16 characters, then name the file via this string of characters?

      If you're specifically interested in just the first 16 characters, you could also look into substr( EXPR, OFFSET, LENGTH). When I saw "host1 BUNCHOFDATAONALINE" I assumed that splitting on whitespace was what you were looking for, but when you phrase it as "one being the first 16 characters", substr comes to mind.

      You may wish to examine the differences between split and substr to see which would suit you better.



      --chargrill
      $/ = q#(\w)# ; sub sig { print scalar reverse join ' ', @_ } + sig map { s$\$/\$/$\$2\$1$g && $_ } split( ' ', ",erckha rlPe erthnoa stJu +" );
      ok, on the split function, can i split $line into two sections, one being the first 16 characters, then name the file via this string of characters?
      Yes, you can, but then chances are that substr or unpack are better suited for the tast. Split works best for splitting on a pattern. Well, more precisely it is exactly for splitting on a pattern!