Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Unable to final...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 10994 of 11065
Post > Topic >>

Unable to finally commit the changes made to some lines in a file

by diwsonal@[EMAIL PROTECTED] (Diwsonal@[EMAIL PROTECTED] ) Apr 26, 2008 at 10:20 PM

Hi,

I am trying to modify my iTunes Playlist and I want to prepend every
playlist name with a specific pseudonym ...

I wrote a perl script using Perl::Tie module. Unfortunately, it doesnt
write the contents of my array to the file after it is done processing
each and every line in the file ...

I am attaching the script and the playlist file ...

Any hint how to finally untie and dump the modified contents to the
same input file i.e. the playlist file ...

Thanks in advance..

--Sonal

Please find the script here:

#!/usr/bin/perl -w

use strict;
use warnings;
use Tie::File;

my $ITUNES_FILE_PATH = "/cygdrive/d/MyDocuments/My Music/iTunes";
my $ITUNES_LIBRARY_FILE_NAME = "iTunes Music Library1.txt";
my $ITUNES_LIBRARY_FILE = "$ITUNES_FILE_PATH/
$ITUNES_LIBRARY_FILE_NAME";
my $PREPEND_PLAYLIST_KEY = "OEL: ";
print "$ITUNES_LIBRARY_FILE\n";

tie my @[EMAIL PROTECTED]
 'Tie::File', $ITUNES_LIBRARY_FILE_NAME or die "Can't
tie $ITUNES_LIBRARY_FILE $!";

for my $i (0..$#lines) {
   if ( $lines[$i] =~ /::/ ) {
	  my $matched_line = $lines[$i];
	  #print "$matched_line\n";
	  my @[EMAIL PROTECTED]
 = split(//, $matched_line);
	  # split with null pattern will split on everything.
	  # so in this case it will be an array of characters
      #print "$#charArray\n";
      #print "$charArray[26]\n";
      #print "$charArray[$#charArray-10]$charArray[$#charArray-11]\n";

      #Use this splice example to insert
      #my @[EMAIL PROTECTED]
 = ("NS", "IE", "Opera");
      #splice @[EMAIL PROTECTED]
 0, 0, 'Mosaic';
      #print "@[EMAIL PROTECTED]
";

      splice(@[EMAIL PROTECTED]
 $#charArray-11, 2);
      splice @[EMAIL PROTECTED]
 26, 0, $PREPEND_PLAYLIST_KEY;
      print "@[EMAIL PROTECTED]
";
   }
}
untie @[EMAIL PROTECTED]
 $ITUNES_LIBRARY_FILE;


Please find the file I am trying to modify here:

	</dict>
			<key>Name</key><string>Sushma Darshan 08::</string>
			<key>Playlist ID</key><integer>61636</integer>
			<key>Playlist Persistent ID</key><string>9C1DDB98AD8E3878</string>
			<key>All Items</key><true/>
			<key>Playlist Items</key>
			<array>
				<dict>
					<key>Track ID</key><integer>16874</integer>
				</array>
		</dict>
	</dict>




 2 Posts in Topic:
Unable to finally commit the changes made to some lines in a fil
diwsonal@[EMAIL PROTECTED  2008-04-26 22:20:32 
Re: Unable to finally commit the changes made to some lines in a
krahnj@[EMAIL PROTECTED]   2008-04-27 07:39:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 23:32:33 CDT 2008.