in reply to split file and put contents in variables?
Hi all, thanks for your effort! I managed to do this, which I think does what I want:
if (-e "test.txt") { open (my $test, '<', "test.txt") or print "Can't open file: $!"; print "opening file \n"; while ( my $line = <$test> ) { my ($a, $b, $c) = split / /, $line; print "$a, $b, $c \n" ; } }
What do you think? I've replaced my variable names with $, $b, $c for testing, just to be quicker.
But I found that I have to match 5 whitespaces, so I was wondering if I can do that with a /d{5}/ or something like that? Instead of matching for / / which needs the spacebar pressed 5 times and doesn't look as nice?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split file and put contents in variables?
by davido (Cardinal) on Feb 02, 2016 at 15:40 UTC | |
|
Re^2: split file and put contents in variables?
by toolic (Bishop) on Feb 02, 2016 at 15:37 UTC | |
by angela2 (Sexton) on Feb 02, 2016 at 15:52 UTC | |
by poj (Abbot) on Feb 02, 2016 at 16:10 UTC | |
by angela2 (Sexton) on Feb 02, 2016 at 16:41 UTC | |
|
Re^2: split file and put contents in variables?
by choroba (Cardinal) on Feb 02, 2016 at 15:48 UTC | |
|
Re^2: split file and put contents in variables?
by ww (Archbishop) on Feb 03, 2016 at 12:38 UTC |