It looks as thought you moved much closer to your target.
BUT, you didn't give us all the errors nor is what you did post, verbatim. Redacting messages when posting simply makes it harder for us to spot where you need help.
Below, with my comments added and the corrections in place, is the code you posted with all the messages generated in the course of running (using the test, perl -c ....) fixing, and running again, until testing produced the heartwarming "syntax OK (BTW, that does NOT mean the code is free of logical errors, nor that it will do what you intended).
use warnings; use strict; open my $fh, '+>', 'output.txt' or die("Can't open the damn file!: $!"); while(my $line == 'mytextfile') # semi-colon removed(run1) & (run2 +)equity test to '==' { # extra empty line removed: HazNav + (not an error) chomp $line; my ($name, $num) = split(/\s+(?=\d)/, $line); # missing semi-col +on inserted (run 1) # some lines have whitespace after the num $num =~ s/\s+//g; if ($num =~ /^\d{4}$/){ $num = "(333)-447-$num"; } elsif ($num =~ /^\d{3}-\d{4}$/){ $num = "(333)-$num"; } print $fh "$name $num\n"; }
Below is the verbatim output when I first ran your code exactly as posted (my comments and corrections for both runs are included).
C:>perl -c delete_me.pl Scalar found where operator expected at delete_me.pl line 16, near ") # some lines have whitespace after the num $num" (Missing operator before $num?) syntax error at delete_me.pl line 8, near ");" syntax error at delete_me.pl line 16, near ") # some lines have whitespace after the num $num " Global symbol "$num" requires explicit package name at delete_me.pl li +ne 16. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 18. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 19. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 19. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 21. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 22. Global symbol "$num" requires explicit package name at delete_me.pl li +ne 22. delete_me.pl had compilation errors.
... and, when those marked "run 1" were fixed, a second iteration, "run 2," told me:
Found = in conditional, should be == at D:\_Perl_\pl_test\delete_me.pl + line 9.
which was fixed by using "==" in the equity test at Ln 9.
In reply to Re^3: total noob trying to format a phone list
by ww
in thread trying to format a list
by sonikd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |