#!/usr/bin/perl use strict; use warnings;

Very good start!    These pragmas should be at the beginning of every Perl program.    (Note that it is spelled Perl, not PERL.)



open FILE, "/home/ajb004/Paradigms/roster.txt" or die $!;

You should usually use the three argument form of open and lexically scoped filehandles and you should probably include the file name in the error message so you know which file failed to open.



$_;

You have a variable in void context which should trigger a warning message.



$_ = $word; s/_/ /g; print "ID: $_\n";

Why are you modifying $_ in this loop when you could just use $word directly?

$word =~ s/_/ /g; print "ID: $word\n";

And since you are also using $_ in the outer loop then this could cause problems in some situations so you should probably avoid using $_ if you can:

while ( my $line = <FILE> ) { my @words = split /,/, $line; foreach my $word ( @words ) { $word =~ s/_/ /g; print "ID: $word\n"; } }

And if you are modifying single characters then the tr/// operator is usually more efficient than the s///g operator.



According to your explanation and data you probably need something like this:

#!/usr/bin/perl use strict; use warnings; my $file = "/home/ajb004/Paradigms/roster.txt"; open my $FILE, '<', $file or die "Cannot open '$file' because: $!"; while ( my $line = <$FILE> ) { chomp $line; $line =~ tr/_/ /; my ( $id, $name, $major, $email ) = split /,/, $line; print <<TEXT; ID: $id Name: $name Major: $major Email: $email TEXT }

In reply to Re: Help Me! by jwkrahn
in thread Help Me! by ajbrewe

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.