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
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
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
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
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
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
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
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
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.
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
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
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
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:/
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.
##
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
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.
>
> ##
> #!
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"
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 () {
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") |
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
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
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.
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
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 |
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
# (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
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
"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 => "$
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
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
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
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
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 => "$_"
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 => "$_",
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
> 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
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
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
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
> -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
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
[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
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
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
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,
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
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,
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
=
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
--
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*$/){
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
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
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,
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
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;
--
: 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
56 matches
Mail list logo