Hi,
flotsan [EMAIL PROTECTED] asked:
I am reading the Perl Camel book - Programming Perl 3rd Ed
and having a bit of trouble to understand some of the ideas
presented in section 2.11.2.
Specifically it is told the following two statements are different:
1) if ($_ = STDIN) { print; }
flotsan wrote:
Hey guys,
Hello,
I am reading the Perl Camel book - Programming Perl 3rd Ed and having a bit
of trouble to understand some of the ideas presented in section 2.11.2.
Specifically it is told the following two statements are different:
1) if ($_ = STDIN) { print; }
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
John W. Krahn wrote:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two of those
are valid input from the readline operator.
John
Should running the above from the command line make a difference? I ran
them both entering 0
flotsan schreef:
it is told the following two statements are
different:
1) if ($_ = STDIN) { print; } # suboptimal: doesn't test defined
2) if (defined($_ = STDIN)) { print; } # best
But as I see it, these two do the same thing
perl -le '
print defined($_) ? \$_\ : undefined
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Dr.Ruud wrote:
flotsan schreef:
it is told the following two statements are
different:
1) if ($_ = STDIN) { print; } # suboptimal: doesn't test defined
2) if (defined($_ = STDIN)) { print; } # best
But as I see it, these two do the same
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I'm trying to figure out how to use stat. I have the following code:
#!/usr/bin/perl -w
use strict;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Mathew Snyder wrote:
I'm trying to figure out how to use stat. I have the following code:
#!/usr/bin/perl -w
use strict;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my
Hi All,
I am not getting the proper output in @vob_rep Array.
Following is my code
# Perl script to change the replica name
use strict;
use warnings;
my $fname = /tmp/vob_list1;
open FILE,,$fname or die $!;
my $fname1 = /tmp/repl_list1;
open FILE1,,$fname1 or die $!;
my $CT =
On 09/21/2006 07:08 PM, chen li wrote:
Hi all,
I read some sections in perltoot. In section
Autoloaded Data Methods I see some line codes as
following:
package Person;
use Carp;
our $AUTOLOAD; # it's a package global
my %fields = (
name= undef,
Xavier Mas i Ramón [mailto:[EMAIL PROTECTED] :
A Dijous 21 Setembre 2006 01:38, [EMAIL PROTECTED] va escriure:
I am looking for some simple perl functions that will return the
current date and time in string format. The purpose is to create a
file with part of the name being the date and
Mathew Snyder wrote:
I'm trying to figure out how to use stat. I have the following code:
You should really figure out how to use readdir
perldoc -f readdir
#!/usr/bin/perl -w
use strict;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Updated my code to look like this:
#!/usr/bin/perl -w
use strict;
my %filenames;
my $file_count = 0;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
next if ($file
Sayed, Irfan (Irfan) wrote:
Hi All,
Hello,
I am not getting the proper output in @vob_rep Array.
What is it doing that you don't want it to do? What is it not doing?
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail:
Mathew Snyder wrote:
John W. Krahn wrote:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two of those
are valid input from the readline operator.
Should running the above from the command line make a difference? I ran
them both entering 0 each time and I got 0 back. This is
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
John W. Krahn wrote:
Mathew Snyder wrote:
John W. Krahn wrote:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two of
those
are valid input from the readline operator.
Should running the above from the command line make a
Mathew Snyder schreef:
#!/usr/bin/perl -w
use strict;
I would change that to:
#!/usr/bin/perl -w
use warnings ;
use strict ;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
push
Thanks... Now I see the one with defined test deals better with those
possible false false inputs:-)
flotsan
John W. Krahn [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Mathew Snyder wrote:
John W. Krahn wrote:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two of
Mathew Snyder schreef:
John W. Krahn:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two
of those are valid input from the readline operator.
Should running the above from the command line make a difference? I
ran them both entering 0 each time and I got 0 back. This is
Mathew Snyder schreef:
Dr.Ruud:
flotsan:
it is told the following two statements are
different:
1) if ($_ = STDIN) { print; } # suboptimal: doesn't test defined
2) if (defined($_ = STDIN)) { print; } # best
But as I see it, these two do the same thing
perl -le '
print
Dr.Ruud schreef:
Mathew Snyder:
#!/usr/bin/perl -w
use strict;
I would change that to:
#!/usr/bin/perl -w
use warnings ;
use strict ;
Oops, the whole point of that was to remove the -w.
See `perldoc perllexwarn`.
--
Affijn, Ruud (now you'll remember even better)
Gewoon is een
On 09/22/2006 02:58 AM, Mathew Snyder wrote:
[...]
my $mod_time = (stat($file))[9];
[...]
If $file is not in the current directory, this won't work.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
John W. Krahn wrote:
#!/usr/bin/perl -w
use strict;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
Why not
Mathew Snyder schreef:
foreach my $file (sort(readdir DH)){
next if ($file =~ /^.%|^..$/);
my $mod_time = (stat($file))[9];
$filenames{$file} = $mod_time;
}
No need to sort before you put things in a hash: hashes don't keep
order.
Try this:
my %file_modtime =
Dr.Ruud wrote:
Mathew Snyder schreef:
John W. Krahn:
Yes, Perl has five false values: undef, (), 0, '' and '0', and two
of those are valid input from the readline operator.
Should running the above from the command line make a difference? I
ran them both entering 0 each time and I got 0 back.
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Dr.Ruud wrote:
Mathew Snyder schreef:
foreach my $file (sort(readdir DH)){
next if ($file =~ /^.%|^..$/);
my $mod_time = (stat($file))[9];
$filenames{$file} = $mod_time;
}
No need to sort before you put things in a
Mathew Snyder wrote:
John W. Krahn wrote:
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
Why not just:
my @filenames = sort readdir DH;
Being new to Perl I want to
Mathew Snyder schreef:
John W. Krahn:
Mathew:
#!/usr/bin/perl -w
use strict;
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
Why not just:
my @filenames
Hi
I have a String which I am forming inside a variable. Say
my
$urlString=http://www.yahoo.com/mail?username=anishkumar_kuserid=1234.0companyname=abc;.
I am printing this string in a browser through CGI. In that case
I am getting the URL with encoded characters for = say now it looks like
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
John W. Krahn wrote:
Mathew Snyder wrote:
John W. Krahn wrote:
my @filenames;
my $processDir = /usr/bin;
opendir DH, $processDir or die cannot open $processDir: $!;
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
Why
Dr.Ruud schreef:
Mathew Snyder:
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
You sort too early.
Ignore that. Just use John's alternative:
my @filenames = sort readdir DH;
or make that
my @filenames = sort grep -f, readdir DH;
Globs are sorted nowadays, I
Mathew Snyder schreef:
I [...]
removed the initialization to 0 for 'my
$file_count' since it doesn't need to be set to an initial value
anyway.
There was nothing wrong with that initialization, but it is OK too to
leave it out.
But: you don't really need that $file_count, do you? The length
Dr.Ruud wrote:
Dr.Ruud schreef:
Mathew Snyder:
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
You sort too early.
Ignore that. Just use John's alternative:
my @filenames = sort readdir DH;
or make that
my @filenames = sort grep -f, readdir DH;
I
John W. Krahn schreef:
Dr.Ruud:
Mathew Snyder:
John W. Krahn:
Yes, Perl has five false values: undef, (), 0, '' and '0', and
two of those are valid input from the readline operator.
Should running the above from the command line make a difference? I
ran them both entering 0 each time and
Anish Kumar K. wrote:
Hi
Hello,
I have a String which I am forming inside a variable. Say
my
$urlString=http://www.yahoo.com/mail?username=anishkumar_kuserid=1234.0companyname=abc;.
I am printing this string in a browser through CGI. In that case
I am getting the URL with encoded
Dr.Ruud wrote:
Dr.Ruud schreef:
Mathew Snyder:
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
You sort too early.
Ignore that. Just use John's alternative:
my @filenames = sort readdir DH;
or make that
my @filenames = sort grep -f, readdir DH;
Did
Mathew Snyder schreef:
Dr.Ruud:
my @filenames = sort grep -f, readdir DH;
I tried this line using $dh. Nothing was getting placed in the array.
Would that be because everything in /usr/bin is an executable file?
Aaargh no, I am making the same mistake as you did: not prepending the
Dr.Ruud wrote:
Mathew Snyder schreef:
Dr.Ruud:
my @filenames = sort grep -f, readdir DH;
I tried this line using $dh. Nothing was getting placed in the array.
Would that be because everything in /usr/bin is an executable file?
Aaargh no, I am making the same mistake as you did: not
Dr.Ruud wrote:
Dr.Ruud schreef:
Mathew Snyder:
foreach my $file (sort(readdir DH)){
push @filenames, $file;
}
You sort too early.
Ignore that. Just use John's alternative:
my @filenames = sort readdir DH;
or make that
my @filenames = sort grep -f, readdir DH;
Please
Mathew Snyder schreef:
Did a bit o' Googling and found how to use the 'not' operator and now
have this line that eliminates the . and .. while still populating the
array in as few lines as possible:
@filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh;
Yes, but that still doesn't filter
Mathew Snyder [EMAIL PROTECTED] wrote:
Did a bit o' Googling and found how to use the 'not' operator
and now have this line that eliminates the . and .. while
still populating the array in as few lines as possible:
@filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh;
You can optimise
Mathew Snyder schreef:
Dr.Ruud:
my @filenames = grep -f $dir/$_, sort readdir DH;
Interesting. The above line returns 1648 items while the following
@filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh;
returns 1650.
That would mean that there are 2 other no-plain-files inside your
I have a String which I am forming inside a variable. Say
my
$urlString=http://www.yahoo.com/mail?username=anishkumar_kus
erid=1234.0companyname=abc.
I am printing this string in a browser through CGI. In that case
I am getting the URL with encoded characters for = say now it
looks
Dr.Ruud wrote:
The '.' and '..' are directories, not plain files.
Some file systems do not have the directories '.' and '..' so they *could*
just be plain files.
You can write
!/^\.$|^\.\.$/
as
!/^\.\.?$/
so also as
!/^[.][.]?$/
Until Perl 5.8.10 comes along literals
John W. Krahn schreef:
Dr.Ruud:
The '.' and '..' are directories, not plain files.
Some file systems do not have the directories '.' and '..' so they
*could* just be plain files.
Right, and that is one of the reasons why I keep bringing -f() up.
I am also testing with a file called |ls -a
Thomas Bätzler schreef:
[ !/^\.$|^\.\.$/ and !/^\.\.?$/ ]
I'm assuming that this regex would be faster, too, since it
does not contain an alternation.
That is hard to say without actual benchmarking: the regex-optimizer
gets better with every new version of perl.
Check also the re=debug
--- Mumia W. [EMAIL PROTECTED]
wrote:
On 09/21/2006 07:08 PM, chen li wrote:
Hi all,
I read some sections in perltoot. In section
Autoloaded Data Methods I see some line codes as
following:
package Person;
use Carp;
our $AUTOLOAD; # it's a package global
Hi all,
I copy some codes from perltoot and write some lines
to see how AUTOLOAD works.
test.pl
#!C:/Perl/bin/perl.exe
use strict;
use warnings;
use Data::Dumper;
use Person;
my $obj=Person-new();
print $obj-name();
print Dumper $obj;
# Person.pm in the
Hi Fred,
Right now, something else has taken first priority, so
I will be writing this code later on. I'll post here and
on CPAN :)
regards
Saurabh
On 9/22/06, hOURS [EMAIL PROTECTED] wrote:
Hello Saurabh,
Did you ever find this? Because I'd be interested as well.
Thanks,
Fred Kittelmann
Dr.Ruud wrote:
Thomas Bätzler schreef:
[ !/^\.$|^\.\.$/ and !/^\.\.?$/ ]
I'm assuming that this regex would be faster, too, since it
does not contain an alternation.
That is hard to say without actual benchmarking: the regex-optimizer
gets better with every new version of perl.
But
John W. Krahn wrote:
Dr.Ruud wrote:
The '.' and '..' are directories, not plain files.
Some file systems do not have the directories '.' and '..' so they *could*
just be plain files.
You can write
!/^\.$|^\.\.$/
as
!/^\.\.?$/
so also as
!/^[.][.]?$/
Until Perl 5.8.10
On 09/22/2006 07:50 AM, chen li wrote:
--- Mumia W. [EMAIL PROTECTED]
wrote:
That redundancy allows you to use inheritance. If
you have a class
Employee, with an expanded set of fields, this
method makes it possible
to add the fields without having to modify each
method that uses them.
On 09/22/2006 08:30 AM, chen li wrote:
Hi all,
I copy some codes from perltoot and write some lines
to see how AUTOLOAD works.
test.pl
#!C:/Perl/bin/perl.exe
use strict;
use warnings;
use Data::Dumper;
use Person;
my $obj=Person-new();
print $obj-name();
Anyone know from experience of a commandline oriented program that can
access S.M.A.R.T. data? In particular hard drive temperature.
This would be a monitor tool for windowsxp machines.
There appears to be a number of Temperature monitoring tools on the
internet but what I'm looking for is one
Mathew wrote:
John W. Krahn wrote:
Dr.Ruud wrote:
You can write
!/^\.$|^\.\.$/
as
!/^\.\.?$/
so also as
!/^[.][.]?$/
Until Perl 5.8.10 comes along literals are more efficient than character
classes so the first one would be better.
I had tried this
/^[.]$|^[..]$/ but had been
[EMAIL PROTECTED] wrote:
Anyone know from experience of a commandline oriented program that can
access S.M.A.R.T. data? In particular hard drive temperature.
This would be a monitor tool for windowsxp machines.
I've never tried it on anything other than Linux, but smartmontools
lists
Hello Everybody,
We can get rows of a 2D array as
$aref = $AoA[$i];
print @$aref; #will print row 'i' as an array
How can I print column 'i' as an array using references? Is there any
other way which doesn't require two 'for loops' to print the columns?
Thanks in advance,
Aditi
--
To
Corey Hickey [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
Anyone know from experience of a commandline oriented program that can
access S.M.A.R.T. data? In particular hard drive temperature.
This would be a monitor tool for windowsxp machines.
I've
Aditi Gupta wrote:
Hello Everybody,
Hello,
We can get rows of a 2D array as
$aref = $AoA[$i];
print @$aref; #will print row 'i' as an array
How can I print column 'i' as an array using references? Is there any
other way which doesn't require two 'for loops' to print the columns?
print
Aditi Gupta wrote:
Hello Everybody,
Hello,
We can get rows of a 2D array as
$aref = $AoA[$i];
print @$aref; #will print row 'i' as an array
How can I print column 'i' as an array using references? Is there any
other way which doesn't require two 'for loops' to print the columns?
joseph [EMAIL PROTECTED] writes:
Corey Hickey [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
Anyone know from experience of a commandline oriented program that can
access S.M.A.R.T. data? In particular hard drive temperature.
This would be a monitor
60 matches
Mail list logo