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.


Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
  1. code
  2. verbatim error and/or warning messages
  3. a coherent explanation of what "doesn't work actually means.

In reply to Re^3: total noob trying to format a phone list by ww
in thread trying to format a list by sonikd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.