On Oct 25, 9:38 pm, [EMAIL PROTECTED] (mAyur) wrote:
> On Oct 23, 6:55 pm, [EMAIL PROTECTED] (Paul Lalli) wrote:
>
>
>
> > On Oct 22, 3:27 pm, [EMAIL PROTECTED] (Ayesha) wrote:
>
> > > Hi all
>
> > > I wrote this code to read a file (in the same directory as the script)
> > > on Win XP
> > > ***************************************************************************­­************************
> > > #!/usr/local/bin/perl
> > > use strict;
> > > use warnings;
>
> > > open(READFILE1,"<./Sample_text_file.txt") or die ("Cannot open the
> > > given file");
>
[snip unrelated stuff]

> > Not relevant to the problem at hand, but you should also be using
> > lexical filehandles instead of global barewords, and get into the
> > habbit of using the three-argument form of open:
>
> > open my $READFILE1, '<', './Sample_text_file.txt' or
> >    die "Cannot open the given file: $!";
>
>
> Some suggestions:
> 1. Instead of using $! for displaying error messages, use $^E. U will
> get more descriptive error messages.
> 2. Quickly going thru this digest i observerd usage of '\' in double
> quotes, this is not recommended. always escape '\' in double quotes
> like this "\\". Heres an example where things can go wrong, lets say
> ur file/directory name starts with 'n' and u say somthing like open
> FILE, "<.\newFile"; "\n" is interpreted as special character by perl
> or for that matter any other language. Correct way would be "open
> FILE, ".\\newFile";
>
> ~emptee.

Your #2 suggestion is not the best in this case/example.
Why did you use a forward slash instead of backslash for the path
separator?

Better advise would be to:
1) Use double quotes (or the qq() operator) only when needed i.e.,
when you need variable interpolation.
2) Use the 3 arg form of open as Paul showed.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to