In a message dated 6/18/2004 3:37:17 AM Eastern Standard Time,
[Email Removed] writes:
QUOTE |
- is it possible to search an array for a certain element, and that the search returns the element index? eg. searching for 156 in the array (123, 456, 156, 1354, 35164, 654656, 654, 846) should give 2 Look into List::Util (first() function) |
QUOTE |
Hi, I have a text file like this: |
QUOTE |
How can i do in Perl to get the first number if the last part of the line doesn't contains extractStat. for exemple here to get only the number 7. Thanks |
QUOTE |
Gunnar Hjalmarsson wrote: Tim Johnson wrote: Chetak Sasalu wrote: |
QUOTE |
That is one way to do it, but maybe you should tell him what it is that the regex does. I remember from my newbie days that it wasn't too useful when people just threw regexes at me without explaining them because they look so daunting before you are used to them. Chetak *could* have done so, but doing it is certainly nothing you can claim that he *should* do. What *should* happen is that the OP ("Jack Jack") start studying some appropriate documentation, ... I didn't say that Chetak's reply was wrong, or that he was somehow remiss in omitting that information. |
QUOTE |
But here's where we differ: Regular expressions are quite possibly one the hardest part of learning effetive Perl programming,and arguably the most valuable. Handing someone a finished regular expression without explaining how it works doesn't really help someone learn how to make their own regular expressions. |
QUOTE |
You maintained that if he really enjoyed the fish he was given and wanted another one bad enough, he would have gone out and found a book on fish and from there derived that fishing would have been the approprate way to get a fish, studied up on it and come back when he had problems fishing |
QUOTE |
Hi List , I have this to print: 1 2 3 with this script but it didn't work: |
QUOTE |
while ($file =~ /^s+(d+).(.+)$/) { |
QUOTE |
print $1n if $2 =~ /extractStat/; |
QUOTE |
I am using following code to validate e-mail addresses if ($mail =~ m/^(w+(.|-))*w+@(w+(.|-)*)+w+$/){ valid }else{ invalid } it will give valid results for all of the following e-mail address [Email Removed] [Email Removed] [Email Removed] [Email Removed] ... but I am not sure about the illegal chars for an e-mail address can someone check above code tell me whether this matches all the valid e-maill address and only the valid e-mail addresses. |
QUOTE |
Not exactly, it has been forked and does technically run in parallel, however 'system' blocks your current process waiting for the child to finish, so your process is in fact running, but it won't be doing any work except for waiting for a signal from the child. There are other ways to have parallel execution, perldoc perlipc perldoc -f fork perldoc -f system Ok. I'll read those in a minute. After reviewing Learning Perl, I |
QUOTE |
Will get you started. "Network Programming with Perl" by Lincoln Stein also has excellent chapters on this subject, though lacks a chapter (probably because of its age) on POE. Haven't purchased that book yet (it's on my amazon wish list however). |
QUOTE |
from what I remember reading and was told as a best practice using exec /.../..../ was recommended over system. For this reason exec does not create a child and therefore does not have to wait. the perl process itself runs the command or program. what are the pros and cons of each? thanks Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams u235sentinel <[Email Removed] 06/25/2004 11:58 AM To: cc: [Email Removed] Subject: Re: 'system' and parallel execution (was: Re: How to call a perl script....) Wiggins d Anconia wrote: Not exactly, it has been forked and does technically run in parallel, however 'system' blocks your current process waiting for the child to finish, so your process is in fact running, but it won't be doing any work except for waiting for a signal from the child. There are other ways to have parallel execution, perldoc perlipc perldoc -f fork perldoc -f system Ok. I'll read those in a minute. After reviewing Learning Perl, I realize I need to open the process as a file handle for parallel operations. Called a "piped open". (page 201 Oreilly Learning Perl). Will get you started. "Network Programming with Perl" by Lincoln Stein also has excellent chapters on this subject, though lacks a chapter (probably because of its age) on POE. Haven't purchased that book yet (it's on my amazon wish list however). I'll check it out. Thanks! |
QUOTE |
Exec will shell out and run whatever exec called. At least I believe the correct term is "shell out". Learning Perl says in page 196 that exec locates the program you called and jumps to it. There is no perl process anymore. So I guess it's more of an exit Perl and run this command sort of thing.. |
QUOTE |
however returns you back to Perl. If you want Perl not to wait you can open a process as a file handle. I haven't tried it however it suggests this will run Perl and your process in parallel. |
QUOTE |
Something to try |
QUOTE |
[Email Removed] wrote: from what I remember reading and was told as a best practice using exec /.../..../ was recommended over system. For this reason exec does not create a child and therefore does not have to wait. the perl process itself runs the command or program. what are the pros and cons of each? thanks Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams u235sentinel <[Email Removed] 06/25/2004 11:58 AM To: cc: [Email Removed] Subject: Re: 'system' and parallel execution (was: Re: How to call a perl script....) Wiggins d Anconia wrote: Not exactly, it has been forked and does technically run in parallel, however 'system' blocks your current process waiting for the child to finish, so your process is in fact running, but it won't be doing any work except for waiting for a signal from the child. There are other ways to have parallel execution, perldoc perlipc perldoc -f fork perldoc -f system Ok. I'll read those in a minute. After reviewing Learning Perl, I realize I need to open the process as a file handle for parallel operations. Called a "piped open". (page 201 Oreilly Learning Perl). Will get you started. "Network Programming with Perl" by Lincoln Stein also has excellent chapters on this subject, though lacks a chapter (probably because of its age) on POE. Haven't purchased that book yet (it's on my amazon wish list however). I'll check it out. Thanks! |
QUOTE |
Exec will shell out and run whatever exec called. At least I believe the correct term is "shell out". Learning Perl says in page 196 that exec locates the program you called and jumps to it. There is no perl process anymore. So I guess it's more of an exit Perl and run this command sort of thing.. |
QUOTE |
however returns you back to Perl. If you want Perl not to wait you can open a process as a file handle. I haven't tried it however it suggests this will run Perl and your process in parallel. |
QUOTE |
Something to try |
QUOTE |
[Email Removed] wrote: from what I remember reading and was told as a best practice using exec /.../..../ was recommended over system. For this reason exec does not create a child and therefore does not have to wait. the perl process itself runs the command or program. what are the pros and cons of each? thanks Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams u235sentinel <[Email Removed] 06/25/2004 11:58 AM To: cc: [Email Removed] Subject: Re: 'system' and parallel execution (was: Re: How to call a perl script....) Wiggins d Anconia wrote: Not exactly, it has been forked and does technically run in parallel, however 'system' blocks your current process waiting for the child to finish, so your process is in fact running, but it won't be doing any work except for waiting for a signal from the child. There are other ways to have parallel execution, perldoc perlipc perldoc -f fork perldoc -f system Ok. I'll read those in a minute. After reviewing Learning Perl, I realize I need to open the process as a file handle for parallel operations. Called a "piped open". (page 201 Oreilly Learning Perl). Will get you started. "Network Programming with Perl" by Lincoln Stein also has excellent chapters on this subject, though lacks a chapter (probably because of its age) on POE. Haven't purchased that book yet (it's on my amazon wish list however). I'll check it out. Thanks! |
QUOTE |
"DBSMITH" == DBSMITH <[Email Removed]> writes: |
QUOTE |
perldoc -f exec Ok. makes sense. |
QUOTE |
Yes, alternatively you can use fork+exec to have a forked process that is non-blocking, the reason to use pipes is so that the two can communicate more easily, this isn't always desired. |
QUOTE |
ok then I think system is more ideal for most situations. |
QUOTE |
It's dangerous to make blanket statements like this. Each is a tool that should be understood and applied in the right manner. I agree with this. Generally system would be the right fit for many of |
QUOTE |
That is why it is more important to understand the concepts of process execution, parallelism, blocking, etc. rather than any one particular function. 'system' is really just a combination of a fork+exec+waitpid model that is easy to use, the backticks are similar to the open pipe model, but generally easier to use as well, the open pipe model is really just a fancy version of the same fork+exec+waitpid model. So some would claim you should use fork+exec+waitpid, because 'system' really just uses them, others would say that is the beauty of Perl, 'system' provides a very good shortcut, assuming it accomplishes the goal. hmm... So system could generate zombie processes? Or a filehandle |
QUOTE |
Wiggins d Anconia wrote: It's dangerous to make blanket statements like this. Each is a tool that should be understood and applied in the right manner. I agree with this. Generally system would be the right fit for many of my Perl programs. However exec has it's place like any tool. That is why it is more important to understand the concepts of process execution, parallelism, blocking, etc. rather than any one particular function. 'system' is really just a combination of a fork+exec+waitpid model that is easy to use, the backticks are similar to the open pipe model, but generally easier to use as well, the open pipe model is really just a fancy version of the same fork+exec+waitpid model. So some would claim you should use fork+exec+waitpid, because 'system' really just uses them, others would say that is the beauty of Perl, 'system' provides a very good shortcut, assuming it accomplishes the goal. hmm... So system could generate zombie processes? Or a filehandle process? I guess it really depends on what we are kicking off and whether it exists cleanly. |
QUOTE |
I'm in a situation wherein I want to brush up on my 'Perl', but have no personal computer. I'm currently reading my way through "Learning |
QUOTE |
Is it possible to use 'Perl' without having to install it on a particular machine? |
QUOTE |
I'm in a situation wherein I want to brush up on my 'Perl', but have no personal computer. I'm currently reading my way through "Learning Pearl", but can't do the exercises because I only have access to 'Windows' machines that do not have Perl installed at all. Is there a way to use Perl on-line from such a machine? Is Perl small enough to be installed on a floppy disk that can be moved from machine to machine? Is it possible to use 'Perl' without having to install it on a particular machine? As the others have pointed out, you can install Perl on windows. You *might* be able to get it to run from a CD provided the drive letter was the same (but this is very theoretical, and might prove difficult). If you are at school there is bound to be a unix box of some sort around that will have it installed, ask around and see if you can get an account to play with Perl. If not at school, you could certainly get a cheap hosting account at an online hoster, pick one with shell access, and practice up your Perl that way, of course that would be more expensive than just buying a computer these days eventually. You could probably get a computer on Ebay for less than $200 and install Linux to avoid the M$ tax..... You might also visit a local Perl Mongers group and ask one of the members if you could have access to their machine, one of them is bound to have a server accessible from the internet and would consider giving another member an account provided you didn't abuse it. |
QUOTE |
... I only have access to 'Windows' machines that do not have Perl installed at all. Is there a way to use Perl on-line from such a machine? |
QUOTE |
Is Perl small enough to be installed on a floppy disk that can be moved from machine to machine? |
QUOTE |
Is it possible to use 'Perl' without having to install it on a particular machine? |
QUOTE |
Rod Za wrote: Hi all, i'm trying to make a code that get a file name (with full path) and change the first char of the filename. Someone can say me if there's a better way to do this?: _BEGIN_ #!/usr/bin/perl -w use strict; my($file) = $ARGV[0]; #receives the filename my $file = shift; (the traditional idiom) my @tmp = split(///,$file); #split the path use File::Basename; my ($name, $path) = fileparse($file); (more portable) $tmp[$#tmp] =~ s/.(w+)/c$1/g; #change the first char of the filename substr($name, 0, 1) = 'c'; (no need for regex) my $IPPFile = join('/',@tmp); #join again path+'/'+filename print "Original Filename: $file - Changed Filename: $IPPFilen"; #print the result _END_ use File::Spec print "Original name: ", $file, " Changed name: ", File::Spec->catfile($path, $name), "n"; You might also have a look at the ubiquitous (and ancient) perl "rename" script: http://www.cpan.org/scripts/nutshell/ch6/rename |
QUOTE |
Hi all, i'm trying to make a code that get a file name (with full path) and change the first char of the filename. Someone can say me if there's a better way to do this?: _BEGIN_ #!/usr/bin/perl -w |
QUOTE |
my($file) = $ARGV[0]; #receives the filename |
QUOTE |
my @tmp = split(///,$file); #split the path |
QUOTE |
$tmp[$#tmp] =~ s/.(w+)/c$1/g; #change the first char of the filename |
QUOTE |
my $IPPFile = join('/',@tmp); #join again path+'/'+filename print "Original Filename: $file - Changed Filename: $IPPFilen"; #print the result _END_ |
QUOTE |
Hello everybody. |
QUOTE |
I am on a new server and have discovered the Directories in the CGI-BIN are visible to everybody. This is, if a type www.mysite.com/cgi-bin I get a list of all the files and subdirectories, and so for every subdirectory. I had never had this issue. |
QUOTE |
What is the best permission for my directories? |
QUOTE |
Now, they are 755, but I'm not sure if changing it will cause the scripts not to run. |
QUOTE |
The other way would be to place an index.html file in every directory causein the files not to get listed, but I'm sure there's a correct way to do it. |
QUOTE |
Hello wiggins, Thanks, My requirement is i have two arrays @element and @size that i have got by splitting. |
QUOTE |
I want to map first element of @element with first element of @size seperated with a colon . (in a loop how should i do it for all elements |
QUOTE |
for eg: file1 : 1 file2 : 2 file3 : 3 so if say print @c i should have output as follows file1 : 1 file2 : 2 file3 : 3 |
QUOTE |
Hi, My perl script which uses CGI module fails to work in Solaris giving Standard HTTP 500 Internal server error.I checked the Apache log. It says "Premature end of script headers:" But it works fine in HPUX and Windows. Is there any thing That has to be take care of in Solaris. |
QUOTE |
Thanks in Advance. |
QUOTE |
Thanx for the help Zentara. Here are a part of my code. I know that I'm doning stuff the long way so if anyone could show me a shorter way it will be helpfull. I wanted to put the sub's that I call into one but how? The progress "meter" have to show that it is still busy scanning the file, as soon as it is done and the file is closed, and the output have been given the meter should stop. I don't want the user to close the program before the job is done. Thanx Hi My program works thru long lists of word. How can I show the user that it is still busy and when it is done. Is there a progressmeter that I can insert into the while loop. To have a perl/tk interface for the user. |
QUOTE |
Hi All, I have the following problem. _Code:_ #!/usr/bin/perl use IO::Socket; my $host=shift @ARGV or die 'need hostname'; my $port=shift @ARGV or die 'need port number'; my $timeout=1; my $socket=IO::Socket::INET->new(PeerAddr=> $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM |
QUOTE |
Timeout => defined($timeout)?$timeout:10) or die "Can't talk to $host at $port"; When I test this on a machine that is currently switched off it takes about a minute to timeout. I the code above I specify $timeout to be 1. Surely it sould timeout after 1 sec. |
QUOTE |
Bob Showalter wrote: ... What platform and what version of Perl and IO::Socket? If I fix the missing comma, it times out properly for me with Perl 5.6.1 on FreeBSD 4.10 SunOS 5.8 This is perl, v5.8.0 built for sun4-solaris-thread-multi - I think Sorry the full code: #!/usr/bin/perl use IO::Socket; my $host=shift @ARGV or die 'need hostname'; my $port=shift @ARGV or die 'need port number'; my $timeout=1; my $socket=IO::Socket::INET->new(PeerAddr=> $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM Timeout => defined($timeout)?$timeout:10) or die "Can't talk to $host at $port"; |
QUOTE |
I want to write a basic http download ( text/binary) script using IO::Socket. Does anyone have any examples anywhere. I know ,everyone must be wondering why I cant use ready modules like LWP. Well I want to auto transfer files to different remote machines. and these machines ( in all flavors of unix/linux ) dont have tools like LWP/ftp/wget/lynx etc and I cant install these on the machines So I plan to run Apache http on my machine with these files run a telnet script from my machine, that will login to these machines and 'write' a simple perl script and then run it from the remote machine and download the necessary files |
QUOTE |
"Unless otherwise stated all methods return either a *true* or *false* value, with *true* meaning that the operation was a success." So sayeth the perldocs, but where is information about the error? With docs like this do you assume it's ${!}, or could it be that other thing (I think I saw something like $^E on this list - what is that?), or some package variable? |
QUOTE |
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, |
QUOTE |
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote perl.org wrote: From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, Methinks that stuff is illegally posted copyrighted information. Several people responded individually with comments like this. If the authors care, shouldn't they contact the ISP? I mean, I can't police the internet single-handedly. And I think O'Reilly has probably already made enough take on this particular snippet... |
QUOTE |
perl.org wrote: From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, Methinks that stuff is illegally posted copyrighted information. |
QUOTE |
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote perl.org wrote: From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm, Methinks that stuff is illegally posted copyrighted information. Several people responded individually with comments like this. If the authors care, shouldn't they contact the ISP? I mean, I can't police the internet single-handedly. And I think O'Reilly has probably already made enough take on this particular snippet... |
QUOTE |
"Perl" == Perl Org <[Email Removed]> writes: |
QUOTE |
Is there away to make a perl scripts in to a .exe and a services for free. -- |
QUOTE |
We really don't need %job at all: my @jobs; foreach ( @lpstat ) { next unless /^ Q$printerE- (d+)s+ (w+)s+d+s+w+s (d+sw+sd+sd{2}:d{2}:d{2}) /ox; push @jobs, { job_name => sprintf 'd%05d-001', $1, job_owner => $2, job_date => $3, }; } |
QUOTE |
I have a vendor-provided OO package and a custom OO package. The custom package does not need a constructor. I want to have a class that inherits from both. It also does not need a constructor - it should use the constructor from the vendor-provided package. I have a problem when my inheriting class tries to call methods my custom superclass - it says the method is not available to the subclass (Can't locate object method "whatever" via package). Does this mean all of the classes need to have constructors? |
QUOTE |
If so, in my constructor, how do I explicitly call the parent constructor? |
QUOTE |
And in the case of multiple inheritence, will it automatically call all constructors in the ISA array? |
QUOTE |
If so, in my constructor, how do I explicitly call the parent constructor? package Bar; @ISA = qw/Foo/; sub new { my $class = shift; bless Foo->new(@_), $class; } |
QUOTE |
Wouldn't you want this instead? package Bar; @ISA = qw/Foo/; sub new { my $s = shift; my $class = ref($s) || $s; my $self = $class->SUPER::new(); bless $self, $class; return $self; } |
QUOTE |
Greetings - I am having trouble locating and using modules that are not in the current directory of a cgi script. For this test, I know the directory structure looks like this: cgi-bin/test/test.cgi cgi-bin/lib/DGStanLib.pm |
QUOTE |
Ron Goral wrote: Greetings - I am having trouble locating and using modules that are not in the current directory of a cgi script. For this test, I know the directory structure looks like this: cgi-bin/test/test.cgi cgi-bin/lib/DGStanLib.pm From: Bob Showalter [mailto:[Email Removed]] Sent: Wednesday, July 07, 2004 10:39 AM To: 'Ron Goral'; Perl Beginners Subject: RE: Trying to locate module in parallel directory Why not the straightforward: use FindBin; use lib "$FindBin::Bin/../lib"; (lifted directly from the FindBin docs) Or why not allow the sysadmin to place the libs wherever he wants and use a SetEnv directive in the web server config to pass PERL5LIB to the CGI scripts and forego use lib altogether? |
QUOTE |
If my Perl contains ${DBI::errstr} I get warnings like this: Ambiguous use of ${DBI::errstr} resolved to $DBI::errstr at (eval 20) line 284. If my Perl contains $DBI::errstr (without the braces) I don't get these warnings. Is there an explanation for this? |
QUOTE |
I can probably figure this out if I spend some time but as I was going through it more questions were raised. Is it possible for a Perl script to check if a subroutine exists in a module without actually invoking that subroutine? |
QUOTE |
I know there is some way to get a reference to a subroutine. If I can figure out how to get this reference (which I assume would be undef or something if I try to get a reference to a subroutine that does not exist) that would probably help, but I am not sure of the syntax or if that's the right approach. |
QUOTE |
Is there any trim function that trims the spaces before and the end of the string? |