Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Shadowsong, here is the output of my directory. I know that music files don't consist of .txt extensions, but this is what I was asked to do for the assignment. So, I made these files names up and went with this type. Inside the files there is supposed to one line that contains the album, minutes, seconds, and genre each separate by ":". The Sun and the Moon:3:47:Alternative

OUTPUT of DIRECTORY:<\p>

The Bravery-Believe.txt

output for file: The Bravery-Believe.txt

The Bouncing Souls-True Believers.txt

output for file: The Bouncing Souls-True Believers.txt

The Kickdrums-Atonement.txt

output for file: The Kickdrums-Atonement.txt

I'm assuming that this:

if ($_ =~ /\.txt/){ chomp $_; my ($artist, $song_title) = split '-', $_, 3; $length{$artist}{$artist} = $artist; $length{$artist}{$song_title} = $song_title; print "$_"; # print this file/directory's name

Could be part of this:

open FH, "<$_" or die $!; print "output for file: $_\n"; while (my $line = <FH>) { print $line; chomp $line; if ($line =~ /\.txt/){ my $artist; my ($album, $minutes, $seconds, $genre) = split ':', $line, 4; $length{$artist}{album} = $album; $length{$artist}{minutes} = $minutes; $length{$artist}{seconds} = $seconds; $length{$artist}{genre} = $genre; print $album, "\n"; }

So, I'm still trying to open the FH of the .txt file and read the contents to get the total amount of the song length for each line and print it out. "Saying this Artist has a total amount of Music". I really appreciate your guidance and patience with me. I know I am a newby at this, but I'm willing to put the time in to learn and get the most out of this language. Thanks, Brandon


In reply to Re^4: I need help with opening a directory and reading files in that directory. by brawal128
in thread I need help with opening a directory and reading files in that directory. by brawal128

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-23 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found