Re: Filehandle within foreach loop

2017-07-16 Thread David Mertens
Yes, and I think that gives us *two* reasons to always explicitly close filehandles. :-) David On Sun, Jul 16, 2017 at 8:00 AM, Shawn H Corey wrote: > On Sun, 16 Jul 2017 07:36:39 -0400 > David Mertens wrote: > > > Also note that lexical filehandles close when they go out of scope > > True but

Re: Filehandle within foreach loop

2017-07-16 Thread Shawn H Corey
On Sun, 16 Jul 2017 07:36:39 -0400 David Mertens wrote: > Also note that lexical filehandles close when they go out of scope True but you should always explicitly close your files. This gives you a chance to report any errors it had, have rather than silently ignoring them. -- Don't stop wher

Re: Filehandle within foreach loop

2017-07-16 Thread David Mertens
Even more readable: FILE: foreach my $file ( @files ) } ... last FILE if (some_condition); ... } Also note that lexical filehandles close when they go out of scope, except for the most recently "stat"ed file. Perl holds a reference to "the most recently stat-ed filehandle" in "the solitary

Re: Filehandle within foreach loop

2017-07-12 Thread Shawn H Corey
On Thu, 13 Jul 2017 00:50:42 +0530 perl kamal wrote: > open (my $FH, $file) or die "could not open file\n"; A quick note: output the file name and error message to have a better idea of what went wrong. open (my $FH, $file) or die "could not open file $file: $!\n"; -- Don't stop where th

Re: Filehandle within foreach loop

2017-07-12 Thread Jim Gibson
If you wish to terminate execution of a foreach loop without iterating over all of the elements (@files, in this case) use the “last” statement: foreach my $file ( @files ) { # process file open( my $fh, ‘<‘, $file ) or die(…); while( my $line = <$fh> ) { # process line } close ($fh) or d

Re: Filehandle within foreach loop

2017-07-12 Thread Chas. Owens
That code will read each line from each file. The problem is likely in the part that says: #[process the lines & hash construction.] What are you doing there? On Wed, Jul 12, 2017 at 3:23 PM perl kamal wrote: > Hello All, > > I would like to read multiple files and process them.But we could r

Re: Filehandle problem

2010-04-29 Thread Akhthar Parvez K
Hi, On Thursday 29 Apr 2010, HACKER Nora wrote: > but I just receive errors: > > Use of uninitialized value in scalar chomp at > /opt/data/magna/wartung/dbmove.pl line 231. > Use of uninitialized value in pattern match (m//) at > /opt/data/magna/wartung/dbmove.pl line 232. > > Could somebod

Re: Filehandle and redirection of STDOUT

2007-11-02 Thread Paul Lalli
On Nov 1, 11:17 pm, [EMAIL PROTECTED] (Rob Dixon) wrote: > Also the call to system() won't write anything to the file you've > opened as it's executed in a separate process: you need to capture the > output from host and print it from within the Perl program. False. Child processes inherit their

Re: Filehandle and redirection of STDOUT

2007-11-02 Thread Paul Lalli
On Nov 1, 10:49 pm, [EMAIL PROTECTED] (Phillip Gonzalez) wrote: > I'm trying to print stdout to a file, then switch back to the default > standard out so that it prints to the screen. This script takes a > list of ip's and does a reverse lookup on them, it then saves the > output to "reverse.

Re: Filehandle and redirection of STDOUT

2007-11-02 Thread John W . Krahn
On Thursday 01 November 2007 20:05, yitzle wrote: > > 1) You can use the backticks (``) or qx// quoting to capture the > output which you can then write to a file 1.5) Use piped open: open PIPE, '-|', 'host', '-W', '1', $ip or die "Cannot open pipe from 'host' $!"; > 2) Use the Perl select com

Re: Filehandle and redirection of STDOUT

2007-11-01 Thread Phillip Gonzalez
Actually, Yes, it does work. I used it today at work to convert about 800 private ip's to their hostnames. Just have to make sure that your file containing ip's is in the same directory as the perl program. I'm very new to perl and was amazed myself that it actually worked! LoL. Thanks

Re: Filehandle and redirection of STDOUT

2007-11-01 Thread Rob Dixon
Phillip Gonzalez wrote: Hi, I'm trying to print stdout to a file, then switch back to the default standard out so that it prints to the screen. This script takes a list of ip's and does a reverse lookup on them, it then saves the output to "reverse.txt". Here's my code: #!/usr/bin/perl u

Re: Filehandle and redirection of STDOUT

2007-11-01 Thread yitzle
1) You can use the backticks (``) or qx// quoting to capture the output which you can then write to a file 2) Use the Perl select command. From the Perldoc: select FILEHANDLE ... a write or a print without a filehandle will default to this FILEHANDLE 3) Use the shell's own redirection. See http:/

Re: FileHandle

2007-11-01 Thread Rob Dixon
Beginner wrote: On 1 Nov 2007 at 19:43, Kaushal Shriyan wrote: Thanks Rob Its working Fine, Now when I am using the below code to write something to file "messages" the below code is not writing the text "write some text " to the file messages. ##

Re: FileHandle

2007-11-01 Thread Paul Lalli
On Nov 1, 10:00 am, [EMAIL PROTECTED] (Beginner) wrote: > On 1 Nov 2007 at 19:20, Kaushal Shriyan wrote: > > > > > > > Hi > > > I am using FileHandle, Below is my code > > > > > #!/usr/bin/perl > > > use warnings; > > use strict; > > > open(LOGFILE, "message

Re: FileHandle

2007-11-01 Thread Beginner
On 1 Nov 2007 at 19:43, Kaushal Shriyan wrote: > Thanks Rob > > Its working Fine, Now when I am using the below code to write something to > file "messages" > the below code is not writing the text "write some text " to the file > messages. > > ## > #!

Re: FileHandle

2007-11-01 Thread Kaushal Shriyan
Thanks Rob Its working Fine, Now when I am using the below code to write something to file "messages" the below code is not writing the text "write some text " to the file messages. ## #!/usr/bin/perl use strict; use warnings; open(LOGFILE, "messages"

Re: FileHandle

2007-11-01 Thread Rob Dixon
Kaushal Shriyan wrote: Hi I am using FileHandle, Below is my code #!/usr/bin/perl use warnings; use strict; open(LOGFILE, "messages") || warn "Could not open messages"; open(DATA, ">/tmp/data") || die "Could not create /tmp/data\n." while () {

Re: FileHandle

2007-11-01 Thread Beginner
On 1 Nov 2007 at 19:20, Kaushal Shriyan wrote: > Hi > > I am using FileHandle, Below is my code > > > #!/usr/bin/perl > > use warnings; > use strict; > > open(LOGFILE, "messages") > || warn "Could not open messages"; > open(DATA, ">/tmp/data") |

Re: FILEHANDLE problem

2007-08-02 Thread Ken Foskey
On Wed, 2007-08-01 at 15:51 -0400, Johnson, Reginald (GTI) wrote: > I don't see what I am doing wrong here. I am trying to print to the > filehandle LINOUT but nothing is being printed to the file. > Ultimately I want to monitor the input file and when it is written to I > want to take the update a

Re: FILEHANDLE problem

2007-08-01 Thread Mumia W.
On 08/01/2007 02:51 PM, Johnson, Reginald (GTI) wrote: I don't see what I am doing wrong here. I am trying to print to the filehandle LINOUT but nothing is being printed to the file. Ultimately I want to monitor the input file and when it is written to I want to take the update and put into anoth

Re: FILEHANDLE problem

2007-08-01 Thread Mr. Shawn H. Corey
Johnson, Reginald (GTI) wrote: I don't see what I am doing wrong here. I am trying to print to the filehandle LINOUT but nothing is being printed to the file. Ultimately I want to monitor the input file and when it is written to I want to take the update and put into another file for processing.

Re: FILEHANDLE question on AIX machine

2006-03-03 Thread Tom Phoenix
On 3/3/06, Families Laws <[EMAIL PROTECTED]> wrote: > what is the purpose of ". 2>&1 |" ? This is a AIX > machine. Thanks. > open(FILEHANDLE, "$PATH_TO_WSADMIN -f $tmpFile > ". ' 2>&1 |'); The '2>&1' part is shell syntax meaning to redirect what would go to filehandle 2 (STDERR) to file

Re: FILEHANDLE question on AIX machine

2006-03-03 Thread The Ghost
I believe this is actually part of the shell command to open that file. It redirects STDOUT and STDERR to a file (shell's, not perl's). As for the "|", I don't know. On Mar 3, 2006, at 1:12 PM, Families Laws wrote: 2>&1 |

Re: filehandle question

2006-01-18 Thread Alan
On Tuesday 17 January 2006 09:30, radhika wrote: [ . . ] > 409$plain_text .= $_ foreach (<$fh>); >close $fh; > --code end-- > > I keep getting this error: > > readline() on closed filehandle $fh at > /home/ars/sys/libperl/site/ARS/REPORTS/AggregateFills.pm line 409. Is that above line

RE: filehandle question

2006-01-17 Thread Charles K. Clarkson
# (Prematurely?) declare lexical variable 405 my $fh; # Get file name from the $file object. 406 my $txtfile = $file->fileName(); # Open file using lexical variable # declared earlier for file handle. # Do not test file opening for success. 407

Re: filehandle question

2006-01-17 Thread Shawn Corey
radhika wrote: Hi, Can someone tell me what is going on in this peice of code? Especially, line 409. --code start-- 405my $fh; 406my $txtfile = $file->fileName(); 407open $fh, $txtfile; open $fh, $txtfile or die "cannot open $txtfile: $!\n"; 408my $plain_text = ''; 409$p

Re: filehandle into a hash?

2005-03-10 Thread Todd W
"Wiggins d'Anconia" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > my @message = ; > > my %mails = ( > From=> "$from", > Subject => "$subject", > Message => join "", @message, > ); > or even just: > my %mails = ( > From=> "$from", > Subject => "$

Re: filehandle into a hash?

2005-03-10 Thread Wiggins d'Anconia
Gavin Henry wrote: On Thursday 10 Mar 2005 20:28, Wiggins d'Anconia wrote: [snip] Also note this can be somewhat dangerous since you will die anytime a message fails to send. The problem is, what if you have 10 messages and message 3 fails? 4-10 don't get sent, the problem is that 1-2 have been se

Re: filehandle into a hash?

2005-03-10 Thread Gavin Henry
On Thursday 10 Mar 2005 20:28, Wiggins d'Anconia wrote: > Gavin Henry wrote: > > Dear all, > > > > I have the following: > > > > #!/usr/bin/perl > > use strict; > > use warnings; > > use Mail::Sendmail; > > > > my $from = '"Test e-mails" <[EMAIL PROTECTED]>'; > > my $subject = 'Testing for survey e

Re: filehandle into a hash?

2005-03-10 Thread Gavin Henry
On Thursday 10 Mar 2005 20:29, Gavin Henry wrote: > I should have searched cpan!! > > http://search.cpan.org/~jimt/Mail-Bulkmail-3.12/ Nevermind, overkill. So my question still stands. > > -- > Just getting into the best language ever... > Fancy a [EMAIL PROTECTED] or something > on http://www.p

Re: filehandle into a hash?

2005-03-10 Thread Gavin Henry
I should have searched cpan!! http://search.cpan.org/~jimt/Mail-Bulkmail-3.12/ -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] or something on http://www.perl.me.uk Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTEC

Re: filehandle into a hash?

2005-03-10 Thread Wiggins d'Anconia
Gavin Henry wrote: Dear all, I have the following: #!/usr/bin/perl use strict; use warnings; use Mail::Sendmail; my $from = '"Test e-mails" <[EMAIL PROTECTED]>'; my $subject = 'Testing for survey e-mail'; open LIST, " open MESSAGE, " my $message = ; foreach () { my %mails = ( To => "$_"

Re: filehandle into a hash?

2005-03-10 Thread Ankur Gupta
Gavin Henry wrote: Dear all, I have the following: #!/usr/bin/perl use strict; use warnings; use Mail::Sendmail; my $from = '"Test e-mails" <[EMAIL PROTECTED]>'; my $subject = 'Testing for survey e-mail'; open LIST, " open MESSAGE, " my $message = ; foreach () { my %mails = ( To => "$_",

Re: FILEHANDLE to print to nothing

2003-08-25 Thread Chuck Fox
There is always /dev/null if you really want it to go to the big bit bucket in the sky. Chuck [EMAIL PROTECTED] wrote: Sure, just use this without an open or close statement... print VOID 'test'; I'm not exactly sure how Perl handles this, but since there is no filehandle called VOID is just

RE: FILEHANDLE to print to nothing

2003-08-25 Thread Dan Muey
> Sure, just use this without an open or close statement... > > print VOID 'test'; > Cool, great for the test! > I'm not exactly sure how Perl handles this, but since there > is no filehandle called VOID is just goes away. > Struct is ok with that but warnings is not. > I wouldn't leave t

RE: FILEHANDLE to print to nothing

2003-08-25 Thread Hanson, Rob
Sure, just use this without an open or close statement... print VOID 'test'; I'm not exactly sure how Perl handles this, but since there is no filehandle called VOID is just goes away. I wouldn't leave this in there when it goes into production, but it shouldn't cause any problems during testing

Re: filehandle problem

2003-03-17 Thread Aim
Hi, I think if you posted some of your code members will be able to help you. Without any code it will not be to easy. regards. aim. [EMAIL PROTECTED] wrote: > How can I see what file handles are pointed at a given file. I am having a

Re: filehandle problem

2003-03-17 Thread Brett W. McCoy
On Mon, 17 Mar 2003 [EMAIL PROTECTED] wrote: > How can I see what file handles are pointed at a given file. I am having a > problem where I open, read, and close a certain file. Then another part of > the script tries to open that same file, but can't. I suspect something is > holding it open. Ano

RE: filehandle problem

2003-03-17 Thread NYIMI Jose (BMB)
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Monday, March 17, 2003 5:04 PM > To: [EMAIL PROTECTED] > Subject: filehandle problem > > > How can I see what file handles are pointed at a given file. > I am having a problem where I open, read, and close

RE: Filehandle modes

2002-09-29 Thread Griggs Rob
Forget it, typo!! Thanks! > -Original Message- > From: Griggs Rob [mailto:[EMAIL PROTECTED]] > Sent: 29 September 2002 22:22 > To: '[EMAIL PROTECTED]' > Subject: Filehandle modes > > > Hi, > > Im trying to read a file and once i have found a particular > line using a > regex i want

Re: Filehandle = blank line???

2002-04-04 Thread John W. Krahn
[Please don't top-post] [154 lines removed from end of message] Allison Ogle wrote: > > My code so far... > > $word = ; > chomp $word; > if ($word=~ /^\s+$/){ > print "There is no word."; } chomp( my $word = ); print "There is no word." unless $word =~ /\S/; John -- use Perl; pro

RE: Filehandle = blank line???

2002-04-04 Thread Allison Ogle
Thanks,it finally worked. -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 4:52 PM To: 'Allison Ogle'; Timothy Johnson; Nikola Janceski; a a Subject: RE: Filehandle = blank line??? That's where the \s* instead of \s

RE: Filehandle = blank line???

2002-04-04 Thread Timothy Johnson
EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 1:48 PM To: Timothy Johnson; Nikola Janceski; a a Subject: RE: Filehandle = blank line??? My code so far... $word = ; chomp $word; if ($word=~ /^\s+$/){ print "There is no word."; } -Original Message- From: Timothy

RE: Filehandle = blank line???

2002-04-04 Thread Allison Ogle
hursday, April 04, 2002 1:35 PM To: Timothy Johnson; Nikola Janceski; a a Subject: RE: Filehandle = blank line??? I did mean $word=. It was just written wrong in the e-mail. Sorry about that. -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04,

RE: Filehandle = blank line???

2002-04-04 Thread Timothy Johnson
mothy Johnson; Nikola Janceski; a a Subject: RE: Filehandle = blank line??? I did mean $word=. It was just written wrong in the e-mail. Sorry about that. -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 4:25 PM To: 'Allison Ogl

RE: Filehandle = blank line???

2002-04-04 Thread Allison Ogle
I did mean $word=. It was just written wrong in the e-mail. Sorry about that. -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 4:25 PM To: 'Allison Ogle'; Nikola Janceski; a a Subject: RE: Filehandle = blank line??? Ok,

RE: Filehandle = blank line???

2002-04-04 Thread Timothy Johnson
Did you mean '$word = ;'? -Original Message- From: Allison Ogle [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 1:27 PM To: Nikola Janceski; a a Subject: RE: Filehandle = blank line??? I will actually be storing the filehandle as a variable and then comparing it. Something like =

Re: Filehandle = blank line???

2002-04-04 Thread bob ackerman
ine') { > ... } > how would I use your suggestion in this case? > > if ($word=~ /^\s*$/) > > doesn't seem to work. > > -Original Message- > From: Nikola Janceski [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 04, 2002 3:53 PM > To: 'Timothy

RE: Filehandle = blank line???

2002-04-04 Thread Allison Ogle
-- From: Nikola Janceski [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 3:53 PM To: 'Timothy Johnson'; 'Michael Stearman'; [EMAIL PROTECTED] Subject: RE: Filehandle = blank line??? he might have chomp it... safer would be: if($_ =~ /^\s*$/){

RE: Filehandle = blank line???

2002-04-04 Thread Nikola Janceski
he might have chomp it... safer would be: if($_ =~ /^\s*$/){ } shorter would be: if(/^\s*$/){ } > -Original Message- > From: Timothy Johnson [mailto:[EMAIL PROTECTED]] > Sent: Thursday, April 04, 2002 3:42 PM > To: 'Michael Stearman'; [EMAIL PR

RE: Filehandle = blank line???

2002-04-04 Thread Timothy Johnson
Maybe if($_ =~ /^\s+$/){ do something... } -Original Message- From: Michael Stearman [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 12:46 PM To: [EMAIL PROTECTED] Subject: Filehandle = blank line??? Hello all, I am stepping through an input file using the

Re: Filehandle problem

2002-01-08 Thread Jos I. Boumans
well, i'm guessing, from the error msg that you got that you have: Too many files specified what is in $cmd? are you sure it's a command NT or Cygwin understand? what happens if you just run the $cmd on a prompt? why don't you check the return value of open? if it fails, what's in $! ? in short,

Re: Filehandle error using Strict

2001-09-05 Thread John W. Krahn
Deborah Strickland wrote: > > Hi all, I've had this question for quite a while and can't find any > reference to it in any of my many Perl books. I want to use the 'strict' > command but whenever I do it always causes an error on any file handles > I have used. What errors are you getting? > I

Re: Filehandle error using Strict

2001-09-05 Thread Ron Smith
What is it that you're trying to do with the file? If you just want to read the contents, using 'filehandles' and 'strict', here's one way to do it: ---snip--- #!/usr/bin/perl -w use strict; open (FILE, "some_file"); while () { print; } close FILE; --

Re: filehandle question

2001-05-04 Thread Timothy Kimball
: is it possible to open a filehandle on a file change one line in that file : without outputing to another file. You can open the file, seek() to a particular position in it, and start overwriting the file at that position, but when you reach the end of that line, you'll keep on writing past it