Simple. Read the file line by line but stop once Perl finds the drive letter. But there's this pesky readline on closed filehandle warning. Any better way to do this?open PLAY, $playlist . ".wpl"; # Get original drive letter my $original_drive_letter; while (<PLAY>) { print "$counter\n"; if (/src=\"(.)\:\\/) { $original_drive_letter = $1; close PLAY; } }
Media player is too dense to figure things out on its own. Perl 5.9, you're my hero.#!perl use strict; use warnings; print "Which playlist do you need to update?\n"; chomp (my $playlist = <STDIN>); $playlist =~ s/(.*)\.wpl/$1/; open PLAY, $playlist . ".wpl"; my $original_drive_letter; my $counter=0; # get drive while (<PLAY>) { ++$counter; print "$counter\n"; if (/src=\"(.)\:\\/) { $original_drive_letter = $1; close PLAY; } } print "It appears the original drive letter is $original_drive_letter. +\n"; print "What would you like the new drive letter to be?\n"; chomp (my $new_drive_letter = <STDIN>); my $no_integrity = 1; while ($no_integrity) { if ($new_drive_letter =~ /^[a-zA-Z]?$/) { print "You want the new drive letter to be $new_drive_letter.\n"; $no_integrity = 0; } else { print "$new_drive_letter doesn't seem to be a valid drive letter. +Let's try again.\n"; print "What do you want the new drive letter to be?\n"; chomp ($new_drive_letter = <STDIN>); $no_integrity = 1; } } print "\nUpdating playlist."; open PLAY, $playlist . ".wpl"; open WRITE, ">temp.wpl"; while (<PLAY>) { s/(="$original_drive_letter:\\)/="$new_drive_letter:\\/g; print WRITE "$_"; print "."; } print "\n\nFinished updating playlist."; close PLAY; close WRITE; unlink ($playlist . ".wpl"); rename "temp.wpl", $playlist . ".wpl" or warn "Couldn't rename: $!";
In reply to Breaking out of a while loop: Is there a better way? by BubbaMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |