in reply to print statement problem

correction:
Greetings,
I am a little confused why the print statement print "$file\n";works fine and prints test.html
but
print statement print "$title[1]\n"; does not print second element of $title
Thanks

Replies are listed 'Best First'.
Re: Re: print statement problem
by PodMaster (Abbot) on Jul 23, 2002 at 06:26 UTC
    #!/usr/bin/perl -w use strict; local $^W=1; use Data::Dumper; my $file ="test.html"; my @title = split (".", $file); print "$file\n"; print "$title[0]\n"; print "$title[1]\n"; print "$title[2]\n"; warn Dumper(\@title); @title = split (/\./, $file); print "$file\n"; print "$title[1]\n"; warn Dumper(\@title); use File::Basename; ## remember, suffix's are regex patterns my ($name,$path,$suffix) = fileparse($file,"\Q.html\E"); print "path $path\n"; print "name $name\n"; print "sufx $suffix\n";
    I suggest you read perlfunc:split as well as the File::Basename documentation, and for gods sake, Use strict warnings and diagnostics or die. As you can see from the above code (which you should run), the reason print "$title[1]\n"; doesn't print anything is because @title is empty, its as simple as that. If you had warnings turned on you would've been warned, so please always use warnings and strict , they'll save you a lot of grief (and use diagnostics if you're not accustomed to using warnings and strict).

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Re: print statement problem
by Nightblade (Beadle) on Jul 23, 2002 at 00:42 UTC
     print "$title[1]\n"; prints second element of @title, not of $title.
    $title and @title is diferent variables in perl;