Re: Absolute noobie question regarding opening files on Windows platform

2007-10-28 Thread Dr.Ruud
mAyur schreef:

> always escape '\' in double quotes like this "\\".

Inside single quotes or q{} too. Try for example:

perl -wle '
  print q{\}
'

-- 
Affijn, Ruud

"Gewoon is een tijger."l

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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-26 Thread Ron Bergin
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/




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-26 Thread mAyur
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");
> > my $record;
> >  while ($record = ) {
> >   print $record;
> >}
>
> > close READFILE1;
>
> > #print "Is this even working? \n"
> > ***­­*
> > It is gives me output that "Cannot open the given file". However, the
> > same program is working on linux/mac platforms, i.e. can open files
> > and read them. To check that I have perl correctly installed I added a
> > print statement at the end. When I block everything regarding opening
> > the file and just have the print statement in the script, the script
> > works OK, implying Perl is installed correctly. Can anyone tell me
> > what is wrong. Can anyone tell me what am I doing wrong here? It seems
> > some Windows specific thing.
>
> You are asking *us* why Perl can't open the file, before you ask
> *Perl* why it can't open the file.  That is most illogical...
>
> Your die() message should include the $! variable, which contains the
> last operating system error.  It will tell you why the file could not
> be opened.  Change your die() to:
>
> die "Cannot open the given file: $!";
>
> 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: $!";
>
> Paul Lalli- Hide quoted text -
>
> - Show quoted text -

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.


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




Re: Another noobie question about perl on Windows - perl running in background

2007-10-25 Thread Matthew Whipple
Ayesha wrote:
> Hi all
>
> Thanks to all who replied to my question yesterday. I am using perl-
> express IDE to write a small perl code. Sometimes the code runs for a
> long time (infinite loop logical error), I close the editor but
> realize that the computer is suddenly running slow. So I have to go to
> task manager and close perl.exe (eating 99% of CPU at that time). I
> wanted to know is there any break execution when using perl-express,
> and on Unix (since I use both types of OS).
>
> Thanks
> Ayesha
>
>
>   
Closing the editor doesn't sound like a good start since the editor and
the running script would be 2 distinct but related processes.  There
should be a break option somewhere near the option that you use to
execute the script (maybe a debug menu).  In Unix the standard Ctrl-C
interrupt should work.  In either case if the script isn't being
responsive (which may be likely if there's bad control logic in it) it
may ignore interrupt signals in which case use process manager in
Windows (as you did), or a kill command in Unix.  The best way to handle
this situation is to make sure you don't get into them...one of the
reasons they are so frowned upon (and you shouldn't just accept
intermittent infinite loops) is because once they get going there may be
no nice solution to stop them. 

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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-25 Thread Ron Bergin
On Oct 23, 6:57 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
> On Oct 23, 12:27 am, [EMAIL PROTECTED] (Ayesha) wrote:
>
> > I was not in the right directory, but I learnt about forward and
> > backward slashed also. Thanks to all who replied
>
> Arg.  This is exactly what I was afraid of.  The post about forward vs
> backwards slashes was wrong.  Do not follow it.  You should ALWAYS use
> front slashes, regardless of Windows vs Unix.   The only thing in
> Windows that requires backslashes is the cmd.exe or command.com
> shells.  You are not using these shells when you write a Perl program.
>
> Paul Lalli

My first reply hasn't propagated yet, so I'll post this update.

The cmd shell excepts both types of slashes.  I first thought that you
needed to use quotes when using forward slashes, but I was wrong.  Try
this simple test.

C:\>notepad c:/boot.ini


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-25 Thread Ron Bergin
On Oct 23, 6:57 am, [EMAIL PROTECTED] (Paul Lalli) wrote:
> On Oct 23, 12:27 am, [EMAIL PROTECTED] (Ayesha) wrote:
>
> > I was not in the right directory, but I learnt about forward and
> > backward slashed also. Thanks to all who replied
>
> Arg.  This is exactly what I was afraid of.  The post about forward vs
> backwards slashes was wrong.  Do not follow it.  You should ALWAYS use
> front slashes, regardless of Windows vs Unix.   The only thing in
> Windows that requires backslashes is the cmd.exe or command.com

That's not entirely correct.  As log as you use proper quoting, you
can use forward slashes in the cmd shell.

Try this:
C:\>cd "c:/Program Files"

C:\Program Files>


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




Re: Another noobie question about perl on Windows - perl running in background

2007-10-23 Thread Jeff Pang
If perl consume your system source large,it mostly has two reasons:

1) Your task is really hard,ie,to handle a huge file.
2) Wrong usage with perl code.

So you'd better to describe clearly what you are doing and how you do
it.Also posting some code piece here is better.

On 10/24/07, Ayesha <[EMAIL PROTECTED]> wrote:
> Hi all
>
> Thanks to all who replied to my question yesterday. I am using perl-
> express IDE to write a small perl code. Sometimes the code runs for a
> long time (infinite loop logical error), I close the editor but
> realize that the computer is suddenly running slow. So I have to go to
> task manager and close perl.exe (eating 99% of CPU at that time). I
> wanted to know is there any break execution when using perl-express,
> and on Unix (since I use both types of OS).
>
> Thanks
> Ayesha
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

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




Another noobie question about perl on Windows - perl running in background

2007-10-23 Thread Ayesha
Hi all

Thanks to all who replied to my question yesterday. I am using perl-
express IDE to write a small perl code. Sometimes the code runs for a
long time (infinite loop logical error), I close the editor but
realize that the computer is suddenly running slow. So I have to go to
task manager and close perl.exe (eating 99% of CPU at that time). I
wanted to know is there any break execution when using perl-express,
and on Unix (since I use both types of OS).

Thanks
Ayesha


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-23 Thread Jenda Krynicky
From: Paul Lalli <[EMAIL PROTECTED]>
> You are asking *us* why Perl can't open the file, before you ask
> *Perl* why it can't open the file.  That is most illogical...
> 
> Your die() message should include the $! variable, which contains the
> last operating system error.  It will tell you why the file could not
> be opened.  Change your die() to:
> 
> die "Cannot open the given file: $!";

You might want to use $^E instead, under some OSes (VMS, OS/2, 
Windows) it contains more details than $!, on other's it's equal to 
$!.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-23 Thread Paul Lalli
On Oct 23, 12:27 am, [EMAIL PROTECTED] (Ayesha) wrote:

> I was not in the right directory, but I learnt about forward and
> backward slashed also. Thanks to all who replied

Arg.  This is exactly what I was afraid of.  The post about forward vs
backwards slashes was wrong.  Do not follow it.  You should ALWAYS use
front slashes, regardless of Windows vs Unix.   The only thing in
Windows that requires backslashes is the cmd.exe or command.com
shells.  You are not using these shells when you write a Perl program.

Paul Lalli


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-23 Thread Paul Lalli
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");
> my $record;
>  while ($record = ) {
>   print $record;
>}
>
> close READFILE1;
>
> #print "Is this even working? \n"
> ***­*
> It is gives me output that "Cannot open the given file". However, the
> same program is working on linux/mac platforms, i.e. can open files
> and read them. To check that I have perl correctly installed I added a
> print statement at the end. When I block everything regarding opening
> the file and just have the print statement in the script, the script
> works OK, implying Perl is installed correctly. Can anyone tell me
> what is wrong. Can anyone tell me what am I doing wrong here? It seems
> some Windows specific thing.

You are asking *us* why Perl can't open the file, before you ask
*Perl* why it can't open the file.  That is most illogical...

Your die() message should include the $! variable, which contains the
last operating system error.  It will tell you why the file could not
be opened.  Change your die() to:

die "Cannot open the given file: $!";

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: $!";

Paul Lalli


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-23 Thread Paul Lalli
On Oct 22, 7:49 pm, [EMAIL PROTECTED] (Yitzle) wrote:
> The '/' is used on Unix, but not on Windows.
> Try replacing it with a '\'
> open(READFILE1,"<.\Sample_text_file.txt") or die ("Cannot open the given 
> file");
> Or maybe just drop the './' entirely.

To the OP, please ignore this post completely.  It is very wrong, and
will lead you to more complicated errors.

Yitzle, I'm sure you mean well, but taking random guesses at what
might be wrong, and worse, at what a solution might be, are far worse
than giving no advice at all.

Paul Lalli


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-23 Thread Ayesha
On Oct 22, 9:32 pm, [EMAIL PROTECTED] (Rob Dixon) wrote:
> 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");
> > my $record;
> >  while ($record = ) {
> >   print $record;
> >}
>
> > close READFILE1;
>
> > #print "Is this even working? \n"
> > ***­*
> > It is gives me output that "Cannot open the given file". However, the
> > same program is working on linux/mac platforms, i.e. can open files
> > and read them. To check that I have perl correctly installed I added a
> > print statement at the end. When I block everything regarding opening
> > the file and just have the print statement in the script, the script
> > works OK, implying Perl is installed correctly. Can anyone tell me
> > what is wrong. Can anyone tell me what am I doing wrong here? It seems
> > some Windows specific thing.
>
> Change your open call to:
>
>   open READFILE1, 'Sample_text_file.txt' or die "Cannot open the file: $!";
>
> and you will see additional information as to why the file couldn't be opened.
>
> Rob- Hide quoted text -
>
> - Show quoted text -

I was not in the right directory, but I learnt about forward and
backward slashed also. Thanks to all who replied

Ayesha


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-22 Thread Rob Dixon

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");
my $record;
 while ($record = ) {
  print $record;
   }

close READFILE1;

#print "Is this even working? \n"

It is gives me output that "Cannot open the given file". However, the
same program is working on linux/mac platforms, i.e. can open files
and read them. To check that I have perl correctly installed I added a
print statement at the end. When I block everything regarding opening
the file and just have the print statement in the script, the script
works OK, implying Perl is installed correctly. Can anyone tell me
what is wrong. Can anyone tell me what am I doing wrong here? It seems
some Windows specific thing.


Change your open call to:

 open READFILE1, 'Sample_text_file.txt' or die "Cannot open the file: $!";

and you will see additional information as to why the file couldn't be opened.

Rob

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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-22 Thread Jenda Krynicky
From: yitzle <[EMAIL PROTECTED]>
> The '/' is used on Unix, but not on Windows.
> Try replacing it with a '\'
> open(READFILE1,"<.\Sample_text_file.txt") or die ("Cannot open the given 
> file");
> Or maybe just drop the './' entirely.

Wrong and wrong.

1) Most system calls do not give a damn whether you use forward or 
backward slashes, The backward slashes are only needed if you are 
passing the path to an external program, in the open() call you can 
use both.

2) If you use a backslash in a doublequoted string you have to DOUBLE 
IT!

Try
print "<.\Sample_text_file.txt";

You are right though that it's best to drop the ./ though.


Ayesha, are you sure the file exists? And are you sure the current 
working directory is what you think it is?

 use Cwd;
 print "CWD: ", getcwd(), "\n";

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Absolute noobie question regarding opening files on Windows platform

2007-10-22 Thread yitzle
The '/' is used on Unix, but not on Windows.
Try replacing it with a '\'
open(READFILE1,"<.\Sample_text_file.txt") or die ("Cannot open the given file");
Or maybe just drop the './' entirely.

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




Absolute noobie question regarding opening files on Windows platform

2007-10-22 Thread Ayesha
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");
my $record;
 while ($record = ) {
  print $record;
   }

close READFILE1;

#print "Is this even working? \n"

It is gives me output that "Cannot open the given file". However, the
same program is working on linux/mac platforms, i.e. can open files
and read them. To check that I have perl correctly installed I added a
print statement at the end. When I block everything regarding opening
the file and just have the print statement in the script, the script
works OK, implying Perl is installed correctly. Can anyone tell me
what is wrong. Can anyone tell me what am I doing wrong here? It seems
some Windows specific thing.

thanks
Ayesha


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




Re: Noobie question

2001-06-14 Thread Michael D . Risser

On Thursday 14 June 2001 08:04 am, you wrote:
> OK I give up
>
> TMTOWTDI?
>

There's More Than One Way To Do It



Re: Noobie question

2001-06-13 Thread Michael D . Risser

At least we were a little more friendly about it, as well as point to some 
resources that would be more help in the long run. And let's not forget 
TMTOWTDI.

--SNIP--
> Fucking typical.
--SNIP--
> I hope this answer is more useful than that suggested by the others.



Re: Noobie question

2001-06-13 Thread Chuck Ivy


On Wednesday, June 13, 2001, at 12:05 PM, Ward, Stefan wrote:

> Does anyone have an example of a way to write a perl script that will 
> go out
> hit a data base table, pull in a column for that table and use that 
> column
> in a dropdown list?  I know what to do once I get that variable 
> selected by
> RTFriendlyM, but couldn't find a clear example of this.
>

Gee, you get three responses with books to read, or URLs to visit, but 
nobody actually answering your question.

Fucking typical.

Excuse me.

Ok.

So you've read the manual, and you're doing your SELECT from the 
database. In many cases, I find myself getting both a value and a human 
readable text for my dropdown.

For sake of argument, let's say your dropdown was a list of web pages, 
and the VALUE for each  is the URL of the page.

So my statements might go something like...

my $sql = "SELECT URL, Name
FROM Links
ORDER BY Name";
my $sth = $dbh->prepare($sql) or die ("Cannot prepare query $sql");
my $sth->execute or die ("Cannot execute query $sql");
my @fields = '';
my $selectstatement = "";
while (@fields = $sth->fetchrow_array) {
$selectstatement .= "$fields[1]";
}
$selectstatement .= "";


I hope this answer is more useful than that suggested by the others.



Re: Noobie question

2001-06-13 Thread Evgeny Goldin (aka Genie)


This should help :

http://dbi.symbolstone.org/
http://search.cpan.org/doc/TIMB/DBI-1.18/DBI.pm





Re: Noobie question

2001-06-13 Thread Michael D . Risser

On Wednesday 13 June 2001 12:22 pm, Peter Scott wrote:
> At 12:05 PM 6/13/01 -0700, Ward, Stefan wrote:
> >Does anyone have an example of a way to write a perl script that will go
> > out hit a data base table, pull in a column for that table and use that
> > column in a dropdown list?  I know what to do once I get that variable
> > selected by RTFriendlyM, but couldn't find a clear example of this.
>
> A good book in this respect is "Writing CGI Application with Perl",
> http://www.amazon.com/exec/obidos/ASIN/0201710145.  Many examples.

You may also want to try "Programming the Perl DBI" by Alligator Descartes & 
Tim Bunce published by O'Reilly

> Peter Scott
> Pacific Systems Design Technologies
> http://www.perldebugged.com



Re: Noobie question

2001-06-13 Thread Peter Scott

At 12:05 PM 6/13/01 -0700, Ward, Stefan wrote:
>Does anyone have an example of a way to write a perl script that will go out
>hit a data base table, pull in a column for that table and use that column
>in a dropdown list?  I know what to do once I get that variable selected by
>RTFriendlyM, but couldn't find a clear example of this.

A good book in this respect is "Writing CGI Application with Perl", 
http://www.amazon.com/exec/obidos/ASIN/0201710145.  Many examples.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com




Noobie question

2001-06-13 Thread Ward, Stefan

Does anyone have an example of a way to write a perl script that will go out
hit a data base table, pull in a column for that table and use that column
in a dropdown list?  I know what to do once I get that variable selected by
RTFriendlyM, but couldn't find a clear example of this.

Thanks,


Stefan Ward
Data Warehouse Eng
Sony Online Entertainment
www.station.sony.com