OLE Permissions in CGI
My guess is that this is more of an IIS 6.0 Security issue but I thought I'd ask some PERL gurus to look through the PERL first. I've written a script that resets the password for a user in our Active Directory for our help desk folks. The script works fine from several computers and works when executed from the command line on the web server. However, when it is executed as CGI from the web server one of the OLE commands (GetObject) doesn't return a value...it should return a hash. It's the line that contains: my $u = Win32::OLE-GetObject($ADsPath). If I put a die statement here the entire script will die. 1) Does the code look good? Its possible that the connection information isn't working but the script works anyway when I'm logged into the console running it via the command line. 2) Does anyone know what the Win32::OLE-GetObject is doing on the server? If the code is good, my guess is that this command is trying to use some resource that I must allow the web server user to access.. Thanks in advance for any light you may be able to shed. Here's a snippet of the code: ###--Create LDAP Connection to Active Directory my $adsinamespaces = CreateObject OLE 'ADsNameSpaces' || die couldn't create; my $ldapnamespace= $adsinamespaces-getobject(,LDAP:)||die didn't work; my $userdsobject=$ldapnamespace-OpenDSObject(LDAP://$server/OU=Users,dc=wsc,d c=western,dc=edu,cn=$admin,ou=Domain Admins,OU=Users,dc=wsc,dc=western,dc=edu,$admin_password,1)||die didn't connect; ###--Bind to specific user account my $ADsPath=LDAP://CN=$user,OU=$ou,OU=Users,DC=WSC,DC=western,DC=edu;; ---The next line fails-## if (my $u = Win32::OLE-GetObject($ADsPath)) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); $u-SetInfo(); print qq( h3strongPassword Reset/strong/h3 pfont face=Arial, Helvetica, sans-serifThe password for $user has been reset to: strong$pass/strong /font/p); } else {print qq( h3strongError!/strong/h3 pfont face=Arial, Helvetica, sans-serifI could not locate $user in the $ou Organizational Unit (OU). br u was |$u| br adspath was |$ADsPath| br userdsobject was |$userdsobject| br adsinamespaces was |$adsinamespaces| br ldap was |$ldapnamespace| /font/p ); } - Mike Garner Computer Services, WSC [EMAIL PROTECTED] 970.943.3123 (voice) 970.943.7069 (fax)
RE: OLE Permissions in CGI
Well, I know nothing about this OLE class, but this seems strange: if (my $u = Win32::OLE-GetObject($ADsPath)) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); ... Perhaps a scoping issue with object $u ? How do you know that method call is bad? From a Perl (yes Perl) perspective, this would personally make me feel warm and fuzzier: my $u = Win32::OLE-GetObject($ADsPath) or die Unable to get object from class OLE with $ADsPath, $!, stopped; if ( defined ($u) ) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); ... -Tom Kinzer -Original Message- From: Mike Garner [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 6:44 AM To: [EMAIL PROTECTED] Subject: OLE Permissions in CGI My guess is that this is more of an IIS 6.0 Security issue but I thought I'd ask some PERL gurus to look through the PERL first. I've written a script that resets the password for a user in our Active Directory for our help desk folks. The script works fine from several computers and works when executed from the command line on the web server. However, when it is executed as CGI from the web server one of the OLE commands (GetObject) doesn't return a value...it should return a hash. It's the line that contains: my $u = Win32::OLE-GetObject($ADsPath). If I put a die statement here the entire script will die. 1) Does the code look good? Its possible that the connection information isn't working but the script works anyway when I'm logged into the console running it via the command line. 2) Does anyone know what the Win32::OLE-GetObject is doing on the server? If the code is good, my guess is that this command is trying to use some resource that I must allow the web server user to access.. Thanks in advance for any light you may be able to shed. Here's a snippet of the code: ###--Create LDAP Connection to Active Directory my $adsinamespaces = CreateObject OLE 'ADsNameSpaces' || die couldn't create; my $ldapnamespace= $adsinamespaces-getobject(,LDAP:)||die didn't work; my $userdsobject=$ldapnamespace-OpenDSObject(LDAP://$server/OU=Users,dc=wsc,d c=western,dc=edu,cn=$admin,ou=Domain Admins,OU=Users,dc=wsc,dc=western,dc=edu,$admin_password,1)||die didn't connect; ###--Bind to specific user account my $ADsPath=LDAP://CN=$user,OU=$ou,OU=Users,DC=WSC,DC=western,DC=edu;; ---The next line fails-## if (my $u = Win32::OLE-GetObject($ADsPath)) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); $u-SetInfo(); print qq( h3strongPassword Reset/strong/h3 pfont face=Arial, Helvetica, sans-serifThe password for $user has been reset to: strong$pass/strong /font/p); } else {print qq( h3strongError!/strong/h3 pfont face=Arial, Helvetica, sans-serifI could not locate $user in the $ou Organizational Unit (OU). br u was |$u| br adspath was |$ADsPath| br userdsobject was |$userdsobject| br adsinamespaces was |$adsinamespaces| br ldap was |$ldapnamespace| /font/p ); } - Mike Garner Computer Services, WSC [EMAIL PROTECTED] 970.943.3123 (voice) 970.943.7069 (fax) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: OLE Permissions in CGI
Basically I had the script written like Tom suggested with a or die for this command but it was terminating the program. I used the if/else so I could print out all my variables to debug. I changed it again so the snippet in questions is as follows: . my $u = Win32::OLE-GetObject($ADsPath) or die print qq(Unable to get object from class OLE with $ADsPath, $!, stopped); if ( defined ($u) ) { $u-SetPassword($pass); $u-Put(pwdLastSet, 0); $u-SetInfo(); } . The result printed to the browser is: Unable to get object from class OLE with LDAP://CN=stu02,OU=Students,OU=Users,DC=WSC,DC=western,DC=edu, , stopped I believe it is this line that fails because I have || die statements on all the previous lines and they seem to run ok. Also when I print their results I'm getting back a value but here I'm not. Any Ideas? - Mike Garner Computer Services, WSC [EMAIL PROTECTED] 970.943.3123 (voice) 970.943.7069 (fax) -Original Message- From: Tom Kinzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 9:34 AM To: [EMAIL PROTECTED] Subject: RE: OLE Permissions in CGI Well, I know nothing about this OLE class, but this seems strange: if (my $u = Win32::OLE-GetObject($ADsPath)) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); ... Perhaps a scoping issue with object $u ? How do you know that method call is bad? From a Perl (yes Perl) perspective, this would personally make me feel warm and fuzzier: my $u = Win32::OLE-GetObject($ADsPath) or die Unable to get object from class OLE with $ADsPath, $!, stopped; if ( defined ($u) ) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); ... -Tom Kinzer -Original Message- From: Mike Garner [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 6:44 AM To: [EMAIL PROTECTED] Subject: OLE Permissions in CGI My guess is that this is more of an IIS 6.0 Security issue but I thought I'd ask some PERL gurus to look through the PERL first. I've written a script that resets the password for a user in our Active Directory for our help desk folks. The script works fine from several computers and works when executed from the command line on the web server. However, when it is executed as CGI from the web server one of the OLE commands (GetObject) doesn't return a value...it should return a hash. It's the line that contains: my $u = Win32::OLE-GetObject($ADsPath). If I put a die statement here the entire script will die. 1) Does the code look good? Its possible that the connection information isn't working but the script works anyway when I'm logged into the console running it via the command line. 2) Does anyone know what the Win32::OLE-GetObject is doing on the server? If the code is good, my guess is that this command is trying to use some resource that I must allow the web server user to access.. Thanks in advance for any light you may be able to shed. Here's a snippet of the code: ###--Create LDAP Connection to Active Directory my $adsinamespaces = CreateObject OLE 'ADsNameSpaces' || die couldn't create; my $ldapnamespace= $adsinamespaces-getobject(,LDAP:)||die didn't work; my $userdsobject=$ldapnamespace-OpenDSObject(LDAP://$server/OU=Users,dc=wsc,d c=western,dc=edu,cn=$admin,ou=Domain Admins,OU=Users,dc=wsc,dc=western,dc=edu,$admin_password,1)||die didn't connect; ###--Bind to specific user account my $ADsPath=LDAP://CN=$user,OU=$ou,OU=Users,DC=WSC,DC=western,DC=edu;; ---The next line fails-## if (my $u = Win32::OLE-GetObject($ADsPath)) { $u-SetPassword( $pass ); $u-Put(pwdLastSet, 0); $u-SetInfo(); print qq( h3strongPassword Reset/strong/h3 pfont face=Arial, Helvetica, sans-serifThe password for $user has been reset to: strong$pass/strong /font/p); } else {print qq( h3strongError!/strong/h3 pfont face=Arial, Helvetica, sans-serifI could not locate $user in the $ou Organizational Unit (OU). br u was |$u| br adspath was |$ADsPath| br userdsobject was |$userdsobject| br adsinamespaces was |$adsinamespaces| br ldap was |$ldapnamespace| /font/p ); } - Mike Garner Computer Services, WSC [EMAIL PROTECTED] 970.943.3123 (voice) 970.943.7069 (fax) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern Match
Since we're now talking about performance issues, somebody should say something about precompiling the regular expression, when you can, with either /o or qr(). I had a process's running time go from 2min 45sec to just under 24sec simply by using qr on the relevant regular expressions. Robert Brown [EMAIL PROTECTED] wrote: Rob Dixon writes: I'm sure you have something useful to say. This seems such a waste of your effort. Rob I think we are failing to communicate. What I am asking is: Does the regular expression mechanism in perl optimize regular expressions such as the one you used earlier in this thread so that the execution overhead is nearly as good as the C approach I outlined earlier in this thread? In other words, for the problem stated earlier, does o(C) = o(perl)? Can I really use regular expressions as my main tool for scanning and modifying strings and expect to get speeds comparable to what I would get with hand tailored code? I hope so, because that would be wonderful. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response __ McAfee VirusScan Online from the Netscape Network. Comprehensive protection for your entire computer. Get your free trial today! http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397 Get AOL Instant Messenger 5.1 free of charge. Download Now! http://aim.aol.com/aimnew/Aim/register.adp?promo=380455 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: SMTP From field using MIME::Lite
It might be my mail server settings. I am using Exchange Server 2003. SMTP MAIL command failed: 5.5.4 Invalid Address I will check into this more. -Original Message- From: Paul Kraus [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 4:21 PM To: Paul Harwood; Beginner Perl Subject: Re: SMTP From field using MIME::Lite This code works for me - #!/usr/bin/perl use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite-new( From = 'Paul Kraus [EMAIL PROTECTED]', To = '[EMAIL PROTECTED]', Subject = 'RE:SMTP From field using MIME::Lite - Test Send', Data = 'This message sent with mime lite' ); MIME::Lite - send ('smtp','my.mailserver.com' ); $msg - send; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
adding path to $PATH
Hi, Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 The regular way to do it in the shell is: setenv PATH my_add_path:$PATH I tried using: system(setenv .); and also: system (csh setenv .); Thanks, Best regards, Pablo -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Help with manipulating a string.
I've got a multiline text box that will feed the ^M at the end of each line. I want to capture it into a single line (which is done), but how do I get it back? Not knowing how many lines there may be with the ^M between them. Currently, I use the old standby: foreach my $rec (@post) { chomp($rec) (Unknown here) = split(/\^M/,$rec); print whatever I need printed\n; }; I'm not sure as to how to declare it, or if there is another way? In Service, Mark Weisman -Original Message- From: Pandey Rajeev-A19514 [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 9:56 PM To: '[EMAIL PROTECTED]' Subject: RE: Help needed on perl wrappers Hi, I was interested in formatted display on screen. I can display ONE text paragraph in any part of the screen with Text::wrap. My question was how to adjust MANY such independent paragraphs in one screen (exactly in a newspaper format where you have 8-10 columns of news items on a single page). I wanted to know is there something like Text::wrap which can do this. Or Text::wrap can handle only one paragraph. If nothing like that exists then I might have to give up Text::wrap and use my own logic to adjust it. Moreover, I also wanted to use Term::Size to adjust the text with changing screen size. Is there any convenient way to do this ? I was looking for readymade stuff. Please suggest. Regards Rajeev -Original Message- From: Tom Kinzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:05 PM To: [EMAIL PROTECTED] Subject: RE: Help needed on perl wrappers I'm trying to figure out WHY you would ever want to create what you are asking for. Why-- is a good question here, because there may be a way to get to the real goal instead of creating this. For instance if it's just going into an HTML document, a table of course, would be easier. Just an example, so WHY are you wanting to do this? If this is really want you want, then: Do you really want a ragged left on the right column? Do you really want to use tabs? I'm thinking spaces would be easier to deal with for this problem and could buy you a justified left margin on the right column. More info please. -Tom Kinzer -Original Message- From: Pandey Rajeev-A19514 [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 8:16 PM To: '[EMAIL PROTECTED]' Subject: Help needed on perl wrappers Hi, I have a text that I read from a file. I want to display the text on the screen in a column in a newspaper style. I do it like this $initial_tab = \t\t; $subsequent_tab = \t\t; print wrap($initial_tab, $subsequent_tab, @text1); print fill($initial_tab, $subsequent_tab, @text1); It will print like this ... I am a boy and I go to school everyday. I have to do a lot of homework and I dont get time to play these days. But if I have more than one independent text i.e. @text2, @text3 to be displayed in different columns, then what shall i do. I want something like this ... I am a boy and I go to schoolShe is a girl and she also goes everyday. I have to do a lot ofto school. I do all her homework homework and I dont get time and she gets plenty of time to to play these days play. Is there any mechanism to achieve this ? Best Regards Rajeev -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: adding path to $PATH
Pablo Cusnir wrote: Hi, Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 The regular way to do it in the shell is: Yours is a Frequently Asked Question. As such, it is answered in the perlfaq documents that come bundled with every distribution of Perl. They can be browsed and searched with the perldoc program. Have a look at perldoc -q environment This will direct you to the Unix FAQ, for example here: http://www.faqs.org/faqs/unix-faq/faq/part2/ (Question 2.8) I cannot find the supposedly much more detailed answer in ftp.wg.omron.co.jp/pub/unix-faq/docs/script-vs-env In short, this should be impossible, but can be done through trickery. -- Helgi Briem T?knideild Landss?minn EHF [EMAIL PROTECTED] S?mi: 550-7466 GSM: 896-7466 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
First module!!! YAAAAY!!! :)
Hi all, Just sat done and put together my FIRST MODULE I went through an edited/modifyed text::parsewords and after lots of testing, editing and playing around with...I got it to work! I didn't realize it could be THIS easy! I have been playing around with h2xs and getting really confused. If I understand this, the *.pm file is standalone and will work on pretty much any platform?? So if I write another one completely from scratch using this rough template it is effectively a perl module that I can distribute?? Surely it can't be THAT easy?? I'm missing something I'm sure of it! :) Any thoughts... Ben package Test::Test; use vars qw($VERSION @ISA @EXPORT); $VERSION = 1.00; require 5.000; use Exporter; @ISA = qw(Exporter); @EXPORT = qw(Test); @EXPORT_OK = qw(); sub Test { my (@parsewords) = @_; foreach $line (@parsewords) { (@linebreakdown)=split(/,/,$line); } return(@linebreakdown); } 1; __END__ =head1 NAME Test::Test - parse text into an array =head1 SYNOPSIS use Test::Test; @teststring = Test(...sometext here delimited by a comma...); =head1 DESCRIPTION =head1 EXAMPLES The sample program: use Test::Test; @ex=Test(Q,Path,Path2,File); print $ex[1]; produces: c:\path __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
opening files on remote computers
Hi, What's the best way to open (for reading) a file on remote computer (in perl) ? Thanks. _ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: opening files on remote computers
Ohad Ohad wrote: Hi, What's the best way to open (for reading) a file on remote computer (in perl) ? Well, what do you need to open the file for? You can do something like mounting the remote FS via NFS, SMB, etc. You can also have an FTP server running on the remote box. You can write client and server Perl programs. If you have sshd running on the remote box, you can probably use scp to get the file. More details please. -- Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I set up bidirectional pipes over a network connection?
On Tue, 2003-12-09 at 17:41, James Edward Gray II wrote: On Dec 9, 2003, at 4:12 PM, Dan Anderson wrote: Well, I was planning to implement the file transfers using Net::FTP or something similar to keep the problems down. But I want every node to be able to talk to other nodes, i.e. each node be able to send every other node a request to download a file and put it in directory . There will be one daemon functioning as the master to regulate, which will provide a database with the IP addresses and port/sockets the other daemons are listening on. Could every box but the main one be running an FTP server and then you only have to write the master script? Well what I had planned was that there would be a module to fetch files and put them where they are supposed to be using FTP, and a brain to listen and talk to the other nodes. I'm just throwing out ideas, to see if anything sparks. This one is probably too clumsy though, if you want to be able to trigger moves from the non-master boxes. Well FTP is a great protocol. It's a private network so I'm not to worried about the fact the files travel it unencrypted. Anybody splicing into my network has enough resources to get me other ways. :-D Doesn't sound to me like your getting out of this one easy, so the suggestion to go for a framework like POE is looking better and better, I would think. Thanks for all your help! -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I set up bidirectional pipes over a network connection?
On Tue, 2003-12-09 at 20:38, John W. Krahn wrote: Dan Anderson wrote: On Tue, 2003-12-09 at 16:31, James Edward Gray II wrote: On Dec 9, 2003, at 3:19 PM, Dan Anderson wrote: I have 2 Linux boxes I want to talk to each other over the local network using a Perl script. Is it possible to set up a bidirectional pipe so that 2 perl daemons can communicate with each other? How would I go about doing this and are there any modules to help? It's very possible and there are many modules to help. Help us help you though, what are you trying to do? It could make a big difference. I'm writing a perl daemon to do two things: back up important files on multiple boxen so if one gets taken out another will survive, and sync files in users directory from a main server -- i.e. I want to be able to do something like $ ./distribute.pl --file and have it sent to all boxen's ~/distributed/ directory. Could you not use NFS to mount the users directories from the main server and use the appropriate RAID arrays and backups on the main server? Actually, that's a good idea too. Thanks for your suggestions! -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: opening files on remote computers
Well, I just want to open the file for reading. somthing like open(FILE, host:file) will be great. Even better if it uses ssh. From: Andrew Gaffney [EMAIL PROTECTED] To: Ohad Ohad [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: opening files on remote computers Date: Wed, 10 Dec 2003 07:43:31 -0600 Ohad Ohad wrote: Hi, What's the best way to open (for reading) a file on remote computer (in perl) ? Well, what do you need to open the file for? You can do something like mounting the remote FS via NFS, SMB, etc. You can also have an FTP server running on the remote box. You can write client and server Perl programs. If you have sshd running on the remote box, you can probably use scp to get the file. More details please. -- Andrew Gaffney _ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Get file size without downloading
Hi, Is there any way to get the size of a file without downloading it? I want to write a program using LWP to download a file only if it is bigger than 3K but smaller than 500K. So I need to know the file size in the first place. Thank you. -u -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
usef wrote: Hi, Is there any way to get the size of a file without downloading it? I want to write a program using LWP to download a file only if it is bigger than 3K but smaller than 500K. So I need to know the file size in the first place. You issue a HEAD request to the server and look at the Content-Length response header. You can use the LWP::Simple module's head method to get this information easily. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Get file size without downloading
Hi, FTP or HTTP? HTTP, but I want to know the method for FTP as well. Thanks -u PS. Sorry Rus for multiple copy *smacks forehead* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: adding path to $PATH
On Wed, 2003-12-10 at 01:09, Pablo Cusnir wrote: Hi, Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 The regular way to do it in the shell is: setenv PATH my_add_path:$PATH I tried using: system(setenv .); and also: system (csh setenv .); You'd need to add it to the CSH equivalent of the .bashrc found in users directory, or /etc/bashrc for it to persist. -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to print ... during download
Thank you guys for quick answers, What if I want to print a ... and calculate the percentage and amount of currently downloaded size during the download process? (wget style), should I create another process to do that? or is there any other alternative? (I will choose the later). Thanks -u -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: passing an array
Mike Blezien wrote: Hello, what is the best way to pass an array to a sub routine, IE. You can't pass an array to a sub. You can only pass a list of scalars. my @fields = qw(one two three); send_array(@fields); sub send_array { my @ary = @_; Whatever you passed ends up in @_. There's no way for the sub to know how this data was passed, if it matters. # do stuff here } is this the most effective way to pass an array to sub routine or is there a better way to do this. If your sub just needs a list of values, what you've done is fine. If your sub somehow needs to know about the @fields array, perhaps to modify it or add or remove elements, you have to pass an array reference. Then you manipulate the array via the reference inside the sub. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
file path pattern matching problem.
Hi all, I'm trying to split apart a filepath...e.g: c:\test\abc\what\somefile.txt The length of the filepath will never be constant... e.g: foreach $line (@Path_Filename) { chomp($line); (@Path_Breakdown) = split(/(\w+\W)(\w+\W)/, $line); } but my biggest problem is how to match a word character \w then match everything until the last \...that will comprise of the file path and the final \ onwards will be the filename incl. or excl. the file extension... I've tried to get the pattern matching to include everything including the \ but it doesn't seem to work. The closest I've gotten is: c:\test\abc\what\somefile.txt c: \test\abc\what\ somefile. txt Any ideas? Is there a pattern character that I'm missing here that allows you to match a certain character and then stop if it's the last one of it's type? Ben __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: opening files on remote computers
Ohad Ohad wrote: Well, I just want to open the file for reading. somthing like open(FILE, host:file) will be great. Even better if it uses ssh. This module from CPAN looks promising: http://search.cpan.org/~ivan/Net-SCP-0.06/SCP.pm -- Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help with manipulating a string.
On Dec 10, 2003, at 1:39 AM, Mark Weisman wrote: I've got a multiline text box that will feed the ^M at the end of each line. I want to capture it into a single line (which is done), but how do I get it back? Not knowing how many lines there may be with the ^M between them. Currently, I use the old standby: foreach my $rec (@post) { chomp($rec) (Unknown here) = split(/\^M/,$rec); print whatever I need printed\n; }; I'm not sure as to how to declare it, or if there is another way? my @lines = split /\^m/, $rec; Is that what you mean? The split just returns a list of the lines, so we can stick that in an array. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to print ... during download
What if I want to print a ... and calculate the percentage and amount of currently downloaded size during the download process? (wget style), should I create another process to do that? or is there any other alternative? (I will choose the later). I chatted about this in my book, SPIDERING HACKS: http://amazon.com/exec/obidos/ASIN/0596005776/disobeycom Thankfully, the discussion and code, are available free online: http://hacks.oreilly.com/pub/h/943 http://disobey.com/d/code/ Depending on your shell, however, one of the examples may not work correctly (the spinner thing, which isn't the display you're looking for. The quick fix is to move the \b to the front of the spinner, not the end). There was more discussion of this on a mailing list, but I can't remember, or find, the URL. -- Morbus Iff ( i put the demon back in codemonkey ) Culture: http://www.disobey.com/ and http://www.gamegrene.com/ My book, Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/ icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: file path pattern matching problem.
Ben - You can use the File::Basename module for this: Your program would be akin to: foreach $line (@Path_Filename) { chomp($line); $filename = basename($line); # gives you the filename with the extension $location = dirname($line); # gives you the location with no trailing / } Here are some examples: ~% perl -MFile::Basename -e'print basename($ARGV[0])' /etc/hosts.equiv hosts.equiv ~% perl -MFile::Basename -e'print dirname($ARGV[0])' /etc/hosts.equiv /etc ~ Jess -Original Message- From: Ben Crane [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 9:22 AM To: [EMAIL PROTECTED] Subject: file path pattern matching problem. Hi all, I'm trying to split apart a filepath...e.g: c:\test\abc\what\somefile.txt The length of the filepath will never be constant... e.g: foreach $line (@Path_Filename) { chomp($line); (@Path_Breakdown) = split(/(\w+\W)(\w+\W)/, $line); } but my biggest problem is how to match a word character \w then match everything until the last \...that will comprise of the file path and the final \ onwards will be the filename incl. or excl. the file extension... I've tried to get the pattern matching to include everything including the \ but it doesn't seem to work. The closest I've gotten is: c:\test\abc\what\somefile.txt c: \test\abc\what\ somefile. txt Any ideas? Is there a pattern character that I'm missing here that allows you to match a certain character and then stop if it's the last one of it's type? Ben __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
usef wrote: Hi, FTP or HTTP? HTTP, but I want to know the method for FTP as well. Thanks -u I think that will work for FTP as well. Give it a try. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: opening files on remote computers
This seems good for COPYing files, I really don't to go there unless I realize I have to . . . I was checking this one : http://search.cpan.org/~nwiger/File-Remote-1.16/Remote.pm But it give me probelms, it complains on ':No such file or directory' for files I know for sure that exists. From: Andrew Gaffney [EMAIL PROTECTED] To: Ohad Ohad [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: opening files on remote computers Date: Wed, 10 Dec 2003 08:22:18 -0600 Ohad Ohad wrote: Well, I just want to open the file for reading. somthing like open(FILE, host:file) will be great. Even better if it uses ssh. This module from CPAN looks promising: http://search.cpan.org/~ivan/Net-SCP-0.06/SCP.pm -- Andrew Gaffney _ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to print ... during download
On Dec 10, 2003, at 8:25 AM, usef wrote: Thank you guys for quick answers, What if I want to print a ... and calculate the percentage and amount of currently downloaded size during the download process? (wget style), should I create another process to do that? or is there any other alternative? (I will choose the later). I believe you're looking for $|, the autoflush variable. If set to a non-zero value, it causes perl to flush output after every print call, even without a \n. Try watching both of these one-liners execute to see what I'm talking about: perl -e 'foreach (1..3) { print time, ; sleep 3; } print \n;' perl -e '$| = 1; foreach (1..3) { print time, ; sleep 3; } print \n;' Hope that helps. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Help needed on perl wrappers
Please bottom post... Hi, I was interested in formatted display on screen. I can display ONE text paragraph in any part of the screen with Text::wrap. My question was how to adjust MANY such independent paragraphs in one screen (exactly in a newspaper format where you have 8-10 columns of news items on a single page). I wanted to know is there something like Text::wrap which can do this. Or Text::wrap can handle only one paragraph. If nothing like that exists then I might have to give up Text::wrap and use my own logic to adjust it. Moreover, I also wanted to use Term::Size to adjust the text with changing screen size. Is there any convenient way to do this ? I was looking for readymade stuff. Please suggest. Have you looked into using ncurses? There is at least one Perl module for manipulating terminals using (n)curses. I have not yet used it for anything in particular, though have seen it used in other apps, centericq for instance. I would think a combination of your text wrapper with curses terminal control should provide what you want... http://danconia.org -Original Message- From: Tom Kinzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:05 PM To: [EMAIL PROTECTED] Subject: RE: Help needed on perl wrappers I'm trying to figure out WHY you would ever want to create what you are asking for. Why-- is a good question here, because there may be a way to get to the real goal instead of creating this. For instance if it's just going into an HTML document, a table of course, would be easier. Just an example, so WHY are you wanting to do this? If this is really want you want, then: Do you really want a ragged left on the right column? Do you really want to use tabs? I'm thinking spaces would be easier to deal with for this problem and could buy you a justified left margin on the right column. More info please. -Tom Kinzer -Original Message- From: Pandey Rajeev-A19514 [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 8:16 PM To: '[EMAIL PROTECTED]' Subject: Help needed on perl wrappers Hi, I have a text that I read from a file. I want to display the text on the screen in a column in a newspaper style. I do it like this $initial_tab = \t\t; $subsequent_tab = \t\t; print wrap($initial_tab, $subsequent_tab, @text1); print fill($initial_tab, $subsequent_tab, @text1); It will print like this ... I am a boy and I go to school everyday. I have to do a lot of homework and I dont get time to play these days. But if I have more than one independent text i.e. @text2, @text3 to be displayed in different columns, then what shall i do. I want something like this ... I am a boy and I go to schoolShe is a girl and she also goes everyday. I have to do a lot ofto school. I do all her homework homework and I dont get time and she gets plenty of time to to play these days play. Is there any mechanism to achieve this ? Best Regards Rajeev -- Boycott the Sugar Bowl! You couldn't pay me to watch that game. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Get file size without downloading
On Wed, 10 Dec 2003, usef wrote: Hi, Is there any way to get the size of a file without downloading it? I want to write a program using LWP to download a file only if it is bigger than 3K but smaller than 500K. So I need to know the file size in the first place. Hi, FTP or HTTP? Rgds Rus -- e: [EMAIL PROTECTED] | Linux + FreeBSD Servers from $12.50/mo e: [EMAIL PROTECTED] | Full Root Access m: +44 7919 373537 | Free Trial Account t: 1-888-327-6330 | http://www.jvds.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
Hello, usef [EMAIL PROTECTED] asked: Is there any way to get the size of a file without downloading it? I want to write a program using LWP to download a file only if it is bigger than 3K but smaller than 500K. So I need to know the file size in the first place. Try making a HEAD request - that should return file size and last modification date. This obviously will not work for CGI URLs. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
Is there any way to get the size of a file without downloading it? I want to write a program using LWP to download a file only if it is bigger than 3K but smaller than 500K. So I need to know the file size in the first place. Try making a HEAD request - that should return file size and last modification date. This obviously will not work for CGI URLs. Something like: my $ua = LWP::UserAgent-new(); my $result = $ua-head($url); my $remote_headers = $result-headers; $total_size = $remote_headers-content_length; -- Morbus Iff ( i put the demon back in codemonkey ) Culture: http://www.disobey.com/ and http://www.gamegrene.com/ My book, Spidering Hacks: http://amazon.com/exec/obidos/ASIN/0596005776/ icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: wildcard File::Copy
On Dec 10, 2003, at 2:11 AM, Ben Crane wrote: Drieux, I'm not passing the filehandle, I want to pass a variable that contains the file path...I'm getting the path from a text file, but that text file doesn't contain extensions and each file has multiple extensions. So I need to copy all files with the same name but different extensions. call me old and slow, but I would do something like: [jeeves: 21:] perl -MFile::Copy -e 'my $filename='junk' ; my @list = $filename.*; File::Copy::copy($_ , 'Target') foreach(@list);' [jeeves: 22:] ls -lR Target total 48 -rw-r--r-- 1 drieux house 251 10 Dec 07:44 junk.cgi -rw-r--r-- 1 drieux house 88 10 Dec 07:44 junk.file -rw-r--r-- 1 drieux house 841 10 Dec 07:44 junk.html -rw-r--r-- 1 drieux house 81 10 Dec 07:44 junk.plx -rw-r--r-- 1 drieux house 97 10 Dec 07:44 junk.rb -rw-r--r-- 1 drieux house 443 10 Dec 07:44 junk.sh [jeeves: 23:] or in the more traditional format my $filename = your_method_here my $target = ...how_do_you_know_this my @list = $filename.*; File::Copy::copy($_ , $target) foreach(@list);' ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I set up bidirectional pipes over a network connection?
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Dan Anderson) writes: I'm writing a perl daemon to do two things: back up important files on multiple boxen so if one gets taken out another will survive, and sync files in users directory from a main server -- i.e. I want to be able to do something like $ ./distribute.pl --file and have it sent to all boxen's ~/distributed/ directory. Some reason you can't use rsync? -- Peter Scott http://www.perldebugged.com/ *** NEW *** http//www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
On Wed, 2003-12-10 at 09:42, Bob Showalter wrote: usef wrote: Hi, FTP or HTTP? HTTP, but I want to know the method for FTP as well. Thanks -u I think that will work for FTP as well. Give it a try. If I type ls when I FTP into somewhere I get a listing of files and size. I would guess either: a) ls is a command in FTP b) there is a corresponding command in the FTP module you are using. -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
pick N random lines from a file
I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from a file: start code-- #!/usr/bin/perl die Usage: $0 N, where N is the number of lines to pick\n if @ARGV 1; $N = shift @ARGV; @pick = (); while () { if (@pick $N) { push @pick, $_; ($r1, $r2) = (rand(@pick), rand(@pick)); ($pick[$r1], $pick[$r2]) = ($pick[$r2], $pick[$r1]); } else { rand($.) = $N and $pick[rand(@pick)] = $_; } } print @pick; -end code--- Could anyone verify if the algorithm is correct? Thanks in advance, -- dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Help needed on perl wrappers
Hmmm, yes I don't know of anything off the top of my head, but if you are doing terminal stuff, I would dig around (starting with CPAN of course) for anything with text based menus where you can map areas of the screen. Perl Tk is pretty cool (and well-named, I might add) and not too difficult in case you have a windows manager running and it's an option. I would argue that learning Tk could be comparable to learning and mussing with a text based menu module unless you can just get lucky enough to dig up exactly a single method that you need. In Tk, you would just drop those two columns into two frames, make 'em scrollable and bob's your uncle - you're done. Good luck, let us know what you end up with and how it worked for you. -Tom Kinzer -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 6:52 AM To: Pandey Rajeev-A19514; '[EMAIL PROTECTED]' Subject: RE: Help needed on perl wrappers Please bottom post... Hi, I was interested in formatted display on screen. I can display ONE text paragraph in any part of the screen with Text::wrap. My question was how to adjust MANY such independent paragraphs in one screen (exactly in a newspaper format where you have 8-10 columns of news items on a single page). I wanted to know is there something like Text::wrap which can do this. Or Text::wrap can handle only one paragraph. If nothing like that exists then I might have to give up Text::wrap and use my own logic to adjust it. Moreover, I also wanted to use Term::Size to adjust the text with changing screen size. Is there any convenient way to do this ? I was looking for readymade stuff. Please suggest. Have you looked into using ncurses? There is at least one Perl module for manipulating terminals using (n)curses. I have not yet used it for anything in particular, though have seen it used in other apps, centericq for instance. I would think a combination of your text wrapper with curses terminal control should provide what you want... http://danconia.org -Original Message- From: Tom Kinzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:05 PM To: [EMAIL PROTECTED] Subject: RE: Help needed on perl wrappers I'm trying to figure out WHY you would ever want to create what you are asking for. Why-- is a good question here, because there may be a way to get to the real goal instead of creating this. For instance if it's just going into an HTML document, a table of course, would be easier. Just an example, so WHY are you wanting to do this? If this is really want you want, then: Do you really want a ragged left on the right column? Do you really want to use tabs? I'm thinking spaces would be easier to deal with for this problem and could buy you a justified left margin on the right column. More info please. -Tom Kinzer -Original Message- From: Pandey Rajeev-A19514 [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 8:16 PM To: '[EMAIL PROTECTED]' Subject: Help needed on perl wrappers Hi, I have a text that I read from a file. I want to display the text on the screen in a column in a newspaper style. I do it like this $initial_tab = \t\t; $subsequent_tab = \t\t; print wrap($initial_tab, $subsequent_tab, @text1); print fill($initial_tab, $subsequent_tab, @text1); It will print like this ... I am a boy and I go to school everyday. I have to do a lot of homework and I dont get time to play these days. But if I have more than one independent text i.e. @text2, @text3 to be displayed in different columns, then what shall i do. I want something like this ... I am a boy and I go to schoolShe is a girl and she also goes everyday. I have to do a lot ofto school. I do all her homework homework and I dont get time and she gets plenty of time to to play these days play. Is there any mechanism to achieve this ? Best Regards Rajeev -- Boycott the Sugar Bowl! You couldn't pay me to watch that game. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Get file size without downloading
Dan Anderson [EMAIL PROTECTED] wrote: On Wed, 2003-12-10 at 09:42, Bob Showalter wrote: usef wrote: Hi, FTP or HTTP? HTTP, but I want to know the method for FTP as well. Thanks -u I think that will work for FTP as well. Give it a try. If I type ls when I FTP into somewhere I get a listing of files and size. I would guess either: a) ls is a command in FTP b) there is a corresponding command in the FTP module you are using. In standard ftp, you can do 'size'. The Net::FTP for perl has a corresponding command also. When you are in standard ftp, just type ftp size yourFile and it will return something like ftp size yourFile 213 12523 where 213 is the message number and (in my case) 12523 is the size of the file. -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
UML meets eXtreme v. BDUF v. SEC
On Dec 9, 2003, at 7:08 PM, R. Joseph Newton wrote: [..] UML? Isn't that the stuff the once-long-ago-knew-how-to-code professional sycophants use to make pretty pictures for execs, so that the execs can go to bed in the warm contented illusion that they actually understand something about the systems they are paying for? [..] Well it sorta depends upon the Politics of the Dance. { Warning: Possible Religious War Material } As an Annotational System for Higher Level documentation UML can provide a common set of glyphs useful both in the BDUF - Big Design Up Front - Design, then Code approach, or as a Follow On Documentation process from say the eXtreme strategy as a prelude to POD. As a 'rapid prototyping tool' I prefer Perl, since we can get from glyph to 'well does that really make sense' reasonably quickly. Then as we start into the process of doing the metrics of analysis can worry about which parts really need to be tightened up to meet 'performance requirements' once the 'bottle neck' is identified. If one does not design, nor document one's code, Then there is no need for UML, or a UML like common glyph set to provide an annotational system. caveat: you may need to review what you are doing if you do not design and/or document your code. This is a Leading Cause of Bad Kharma! Do NOT DO THIS! { Having convinced an associate who has written man pages in Raw roff since the Epoch to float over to POD, it is uh, scary, since his c-code docs now comes in three flavors, POD, the manified Pod, and the html'ized Pod... So getting to POD has value outside of merely Perl. But I can also read his whiteBoard Glyphs and go Oh, one of those types of OLTP's... But this also means I have to UML-ize it so that the Glyph Set is more 'portable' to humans who have color perception, and do not dream in ASCII art... } Like all annotational systems between the designer and the implemented machine language sequence of bits that the CPU may BARF on, it is subject to various abuses. But the defect is NOT in UML, but in the persons hurling BuzzPhraseDuJure in lieu of actual technical stuff. IF you need to KarlRove the material, you should be doing this in PowerPoint. It should NOT contain any actual Technical Information that can be used by the SEC and/or Justice Department Investigators or Prosecutors in subsequent litigation or indictments for violations of SEC Regulations and/or Other possible Felony Indictments. { consult with your solicitor prior to recieving the warrents... } IF the PowerPoint Wars leak into Engineering, to bloat out the UML wars, it is time to float your resume. They will not be worrying about delivering technical solutions, and are in the Power Dive of Spin Doctoring. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern Match
Before I finally burst my cyanide capsule, may I.. ? Rj wrote: Rob Dixon writes: I didn't think it was slick at all. In fact I was disappointed that it looked such a mess, but I don't see a better way. Yes, it is indeed a mess, not only syntacticly, but also semantically. What is a syntactic mess? And, even more obscurely, what is a semantic mess? While it might make a good teaching example to show what you can do in a perl regex, it might not be a very good way to do what is ultimately accomplished. The stark realisation is that an infinite majority of problems have no solution at all. This is a Perl newsgroup. First, a regular expression pattern match is conducted to find all chars in the string that are in the desired special processing range. Note that these are each individual characters, not substrings, so the regex match is gross overkill from a computational complexity point of view. Second, all that is desired is to insert a circumflex and then the character plus a bias to make it printable. I've never before seen a software solution reverse-engineered as far as the documentation plus obfuscations! As far as possible a piece of software should be a description of what is to be done: that is what compilers/interpreters/assemblers/shell languages are for. Ideally what I should be able to write is: replace all control characters with their printable equivalents It is only the rigour of programming languages that prevents this. And why most companies still employ people. Now if this is all that has to be done, and you want to do it to a bunch of large files, then the way you show is a poor way to do it. Now Yes, it is indeed a mess, not only syntacticly, but also semantically. and the way you show is a poor way to do it is downright rude. Especially without an alternative option. Do you want to be taken seriously or what? I wrote an algorithm. If you have a problem with how well (in whatever sense) a computer executes that algorithm then you have an issue with the originators of the language and its implementors. I for one think that Perl is one of the best- conceived languages and certainly the best choice for any stand- alone program. A simple C program could be written to get a character from stdin, check it in an if statement to see if it is in the desired range, and then output the circumflex followied by the biased character to stdout if it is in the range, or else just output the character. This simple one-char-at-a-time streaming filter approach would be considerably simpler computationally than the method you provide. How are you so sure that that's not how my algorithm is implemented by the compiler? Now if you only need to do this to massage a few lines of output in a program with a much larger overall purpose, then perhaps your example is the way to go. Or perhaps it's the best way to go anyway? My question is, how does perl's regex compiler handle the code you gave? Does it optimize it to a similar level of complexity as my C example, or does it smash it with a one- size-fits-all regular expression engine? I know regular expressions can be highly optimized at compile time, so this is an important question. If the regex is sufficiently optimized, then it would always be the way to go. 'Sufficiently'? Why do you need to know? I know very well that I can write something in Intel assembler that will perform far faster than your C program. But I don't need to. I still don't understand your point. Just how fast do you need this thing to go? Why not just put stripes on it? Rob BTW have you read the context of your sig? Rj wrote: And there came a writing to him from Elijah [2Ch 21:12] R. J. Brown III [EMAIL PROTECTED] http://www.elilabs.com/~rj voice 847 543-4060 Elijah Laboratories Inc. 457 Signal Lane, Grayslake IL 60030 fax 847 543-4061 - M o d e l i n g t h e M e t h o d s o f t h e M i n d -- 2 Chronicles 21:12,13 Jehoram received a letter from Elijah the prophet, which said: This is what the LORD, the God of your father David, says: 'You have not walked in the ways of your father Jehoshaphat or of Asa king of Judah. But you have walked in the ways of the kings of Israel, and you have led Judah and the people of Jerusalem to prostitute themselves, just as the house of Ahab did. You have also murdered your own brothers, members of your father's house, men who were better than you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
[ADMIN] Re: Pattern Match
It was Wednesday, December 10, 2003 when Rob Dixon took the soap box, saying: : Before I finally burst my cyanide capsule, may I.. ? No, you may not. I find walking around the block a good way to cool off. Counting to ten has never done it for me, but you may try. *Both* of you. Thanks for killing the personal tension between you two, on this list, we're throwing in the white flag. :-) Casey West -- Once you dump SOLARIS, you're just a hop, skip and a jump from realizing that your US$20k Sun E250 can be replaced with US$5k worth of Intel-based equipment from a reputable vendor, such as IBM. Dream on. -- Abigail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
1 doubt.
perl t.pl Name main::FH used only once: possible typo at t.pl line 6. cat t.pl #!/usr/bin/perl use strict; use warnings; open FH, out.dat; Why am i getting this warning? When i remove the warnings,this goes off? Is there any problem if i not include use warnings line? Quick reply is highly appreciated regards -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
UML meets eXtreme v. BDUF v. SEC
(I am deliberately TOP POSTING my reply to this because it seems most appropriate.) B E A U T I F U L L Y S A I D ! ! ! Drieux writes: On Dec 9, 2003, at 7:08 PM, R. Joseph Newton wrote: [..] UML? Isn't that the stuff the once-long-ago-knew-how-to-code professional sycophants use to make pretty pictures for execs, so that the execs can go to bed in the warm contented illusion that they actually understand something about the systems they are paying for? [..] Well it sorta depends upon the Politics of the Dance. { Warning: Possible Religious War Material } As an Annotational System for Higher Level documentation UML can provide a common set of glyphs useful both in the BDUF - Big Design Up Front - Design, then Code approach, or as a Follow On Documentation process from say the eXtreme strategy as a prelude to POD. As a 'rapid prototyping tool' I prefer Perl, since we can get from glyph to 'well does that really make sense' reasonably quickly. Then as we start into the process of doing the metrics of analysis can worry about which parts really need to be tightened up to meet 'performance requirements' once the 'bottle neck' is identified. If one does not design, nor document one's code, Then there is no need for UML, or a UML like common glyph set to provide an annotational system. caveat: you may need to review what you are doing if you do not design and/or document your code. This is a Leading Cause of Bad Kharma! Do NOT DO THIS! { Having convinced an associate who has written man pages in Raw roff since the Epoch to float over to POD, it is uh, scary, since his c-code docs now comes in three flavors, POD, the manified Pod, and the html'ized Pod... So getting to POD has value outside of merely Perl. But I can also read his whiteBoard Glyphs and go Oh, one of those types of OLTP's... But this also means I have to UML-ize it so that the Glyph Set is more 'portable' to humans who have color perception, and do not dream in ASCII art... } Like all annotational systems between the designer and the implemented machine language sequence of bits that the CPU may BARF on, it is subject to various abuses. But the defect is NOT in UML, but in the persons hurling BuzzPhraseDuJure in lieu of actual technical stuff. IF you need to KarlRove the material, you should be doing this in PowerPoint. It should NOT contain any actual Technical Information that can be used by the SEC and/or Justice Department Investigators or Prosecutors in subsequent litigation or indictments for violations of SEC Regulations and/or Other possible Felony Indictments. { consult with your solicitor prior to recieving the warrents... } IF the PowerPoint Wars leak into Engineering, to bloat out the UML wars, it is time to float your resume. They will not be worrying about delivering technical solutions, and are in the Power Dive of Spin Doctoring. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: 1 doubt.
Name main::FH used only once: possible typo at t.pl line 6. It's because it's used only once ;o) . If you just declare something (variable, filehandle etc.) but don't use it, something's probably wrong with your code (such as a typo). If you try reading or writing using that filehandle the error will go away. This email has been scanned for all viruses by the MessageLabs Email Security System. For more information on a proactive email security service working around the clock, around the globe, visit http://www.messagelabs.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: 1 doubt.
On Dec 11, 2003, at 3:27 AM, Ajey Kulkarni wrote: perl t.pl Name main::FH used only once: possible typo at t.pl line 6. cat t.pl #!/usr/bin/perl use strict; use warnings; open FH, out.dat; Why am i getting this warning? When i remove the warnings,this goes off? Is there any problem if i not include use warnings line? As the warning say, you used FH only once. You open() a file and do nothing with it. Perl's just making sure you are aware of the issue. Once you start using the file Perl will be quite about it. While you're at it, don't forget to check that the file opened properly: open FH, 'out.dat' or die File error: $!\n; James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: 1 doubt.
On Thu, Dec 11, 2003 at 09:27:48AM +, Ajey Kulkarni wrote: perl t.pl Name main::FH used only once: possible typo at t.pl line 6. You opened a file, but you do not read from the file. Just opened it. This doesn't make much sense. So you get a warning. cat t.pl #!/usr/bin/perl use strict; use warnings; open FH, out.dat; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: [ADMIN] Re: Pattern Match
Casey West wrote: : Before I finally burst my cyanide capsule, may I.. ? No, you may not. I find walking around the block a good way to cool off. Counting to ten has never done it for me, but you may try. *Both* of you. Thanks for killing the personal tension between you two, on this list, we're throwing in the white flag. :-) Thanks Casey. I was trying for a resolution rather than an impasse but, hey! Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: [ADMIN] Re: Pattern Match
It was Wednesday, December 10, 2003 when Rob Dixon took the soap box, saying: : Casey West wrote: : : : Before I finally burst my cyanide capsule, may I.. ? : : No, you may not. : : I find walking around the block a good way to cool off. Counting to ten : has never done it for me, but you may try. *Both* of you. : : Thanks for killing the personal tension between you two, on this list, : we're throwing in the white flag. :-) : : Thanks Casey. : : I was trying for a resolution rather than an impasse but, hey! Stay on topic, and be courteous, and you can resolve your technical differences. Resolve the rest privately. Casey West -- In case of fire, do your utmost to alarm the hotel porter. --In a Vienna hotel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: 1 doubt.
It's a warning. If you turn it off you wont get it :) Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [EMAIL PROTECTED] -Original Message- From: Ajey Kulkarni [mailto:[EMAIL PROTECTED] Sent: Thursday, December 11, 2003 4:28 AM To: [EMAIL PROTECTED] Subject:1 doubt. perl t.pl Name main::FH used only once: possible typo at t.pl line 6. cat t.pl #!/usr/bin/perl use strict; use warnings; open FH, out.dat; Why am i getting this warning? When i remove the warnings,this goes off? Is there any problem if i not include use warnings line? Quick reply is highly appreciated regards -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
2nd doubt.
HI again. I'm tryign to modify the .procmailrc file Initially the file looks liek this -- :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0: * ^X-Spam-Status: Yes | dmail +mail/junk :0 | dmail +INBOX the file after modificatin should look like :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 wB * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w * ^X-Spam-Status: Yes | dmail +mail/junk :0 w | dmail +INBOX This is my first realtime use of perl,and i'm kinda stomped. I'm able to read each line in the procmailrc file,but just ened to parse the (line by line) and modify the contents. Help required. -Aj -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: pick N random lines from a file
On Wed, 2003-12-10 at 11:12, David Garamond wrote: I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from a file: start code-- #!/usr/bin/perl die Usage: $0 N, where N is the number of lines to pick\n if @ARGV 1; $N = shift @ARGV; @pick = (); while () { if (@pick $N) { push @pick, $_; ($r1, $r2) = (rand(@pick), rand(@pick)); ($pick[$r1], $pick[$r2]) = ($pick[$r2], $pick[$r1]); } else { rand($.) = $N and $pick[rand(@pick)] = $_; } } print @pick; -end code--- Could anyone verify if the algorithm is correct? Dave, Yes, your algorithm seems to work. I just made a file with a number (1-20) on each line, then ran it and it seems to work just fine. HTH, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: 2nd doubt.
Not to be a pest but try and be more descriptive in your subject. It saves everyone time in trying to decide on what they can help you with. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern Match
From: Robert Brown [EMAIL PROTECTED] Casey West writes: : Does the regular expression mechanism in perl optimize regular : expressions such as the one you used earlier in this thread so that : the execution overhead is nearly as good as the C approach I outlined : earlier in this thread? In other words, for the problem stated : earlier, does o(C) = o(perl)?The answer is, C almost always going to be much faster almost all the time, YMMV. Really the only way to tell is with tests and benchmarks, but you can almost always bet on C. Sorry again for my confusing way of expressing myself. Although I wrote my example in C, that was because I am a novice perl programmer, but an experienced C programmer, so I expressed my algorithm in C. The idea was to compare the execution effeciency of a perl regular expression approach to a less syntacticly compact algorithmic approach using loops and conditionals, still written in perl, to edit the string. I just used C so you all would not beat me up over perl syntax details instead of answering the real question. Is perl going to be comparably efficient whichever way you code it, or is the explicit test and loop approach usually going to be faster for simple jobs? I want to know when to use the regex approach and when not to. 1. Perl builtins and especialy the regular expression engine is heavily optimized. So it might very well be quicker to use a regexp from Perl than to implement the same stuff in C. Unless you spend a lot of time tweaking the code. 2. One regexp (assuming its created well) will almost always be quicker than several loops and ifs in Perl. While you should not use a regexp where the normal functions suffice, you should not go into great lengths implementing something that would be simple as a regexp. It'll be harder to maintain and most probably slower. 3. If you really need to know which solution is quicker use Benchmark; 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/ http://learn.perl.org/first-response
Re: pick N random lines from a file
Kevin Old writes: On Wed, 2003-12-10 at 11:12, David Garamond wrote: I'm trying to extend the Perl cookbook recipe on how to pick a random line from a file: #!/usr/bin/perl rand($.) 1 ($line = $_) while ; print $line; for picking up to N random lines from a file: The classical algorithm for this is found in Knuth's Art of computer cproagramming, vol 2, seminumerical algorithms on pp 121-123. Here is a C++ routine I wrote several years ago that implements the algorithm given in Knuth; perhaps it will help you write one in C: 9: // Knuth's random sample algotithm S, Seminumerical Algorithms pp 121-123. 10: // 11: void sample(prng rand, long* slot, long n, long N) { // take a random sample 12: long t; // counts up to N 13: long m = 0; // counts up to n 15: for (t = 0; m n; t++) { // loop till all n slots are chosen 16: if (rand.next(0, N - t) n - m) { // do we select this from 0..N? 17: slot[m++] = t;// yes, 18: } 19: } 20: } -- And there came a writing to him from Elijah [2Ch 21:12] R. J. Brown III [EMAIL PROTECTED] http://www.elilabs.com/~rj voice 847 543-4060 Elijah Laboratories Inc. 457 Signal Lane, Grayslake IL 60030 fax 847 543-4061 - M o d e l i n g t h e M e t h o d s o f t h e M i n d -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern Match
On Wed, 10 Dec 2003 20:11:26 +0100, Jenda Krynicky [EMAIL PROTECTED] wrote: 1. Perl builtins and especialy the regular expression engine is heavily optimized. So it might very well be quicker to use a regexp from Perl than to implement the same stuff in C. Unless you spend a lot of time tweaking the code. 2. One regexp (assuming its created well) will almost always be quicker than several loops and ifs in Perl. While you should not use a regexp where the normal functions suffice, you should not go into great lengths implementing something that would be simple as a regexp. It'll be harder to maintain and most probably slower. 3. If you really need to know which solution is quicker use Benchmark; Jenda Thank you, Jenda! That is the kind of answer I was looking for. -- And there came a writing to him from Elijah [2Ch 21:12] R. J. Brown III [EMAIL PROTECTED] http://www.elilabs.com/~rj voice 847 543-4060 Elijah Laboratories Inc. 457 Signal Lane, Grayslake IL 60030 fax 847 543-4061 - M o d e l i n g t h e M e t h o d s o f t h e M i n d -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: file path pattern matching problem.
Ben Crane wrote: Hi all, Hello, I'm trying to split apart a filepath...e.g: c:\test\abc\what\somefile.txt The length of the filepath will never be constant... $ perl -le' use File::Spec; my $path = q[c:\test\abc\what\somefile.txt]; my ( $vol, $dir, $file ) = File::Spec-splitpath( $path ); print qq[ $vol $dir $file ]; my @dirs = File::Spec-splitdir( $dir ); print map qq[ $_ ], @dirs; ' c: \test\abc\what\ somefile.txt test abc what John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: file path pattern matching problem.
Yes! And use Basename too. these will also give you the advantage of making your programs more portable! -Tom Kinzer -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 11:37 AM To: [EMAIL PROTECTED] Subject: Re: file path pattern matching problem. Ben Crane wrote: Hi all, Hello, I'm trying to split apart a filepath...e.g: c:\test\abc\what\somefile.txt The length of the filepath will never be constant... $ perl -le' use File::Spec; my $path = q[c:\test\abc\what\somefile.txt]; my ( $vol, $dir, $file ) = File::Spec-splitpath( $path ); print qq[ $vol $dir $file ]; my @dirs = File::Spec-splitdir( $dir ); print map qq[ $_ ], @dirs; ' c: \test\abc\what\ somefile.txt test abc what John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Match the first 3 characters of 2 words?
What is the easiest way to test the first 3 characters of two words for a match. IE: dasf test dasg to return positive. rod. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Match the first 3 characters of 2 words?
Response at end of message... -Original Message- From: Rod [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:19 PM To: '[EMAIL PROTECTED]' Subject: Match the first 3 characters of 2 words? What is the easiest way to test the first 3 characters of two words for a match. IE: dasf test dasg to return positive. -My Response- Use the \b word boundary in your regex for the beginning of the word: if ($var =~ /\bdas/) { print $var begins with 'das'\n } else { print $var doesn't begin with 'das'\n } /\/\ark -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Match the first 3 characters of 2 words?
On Dec 10, 2003, at 2:19 PM, Rod wrote: What is the easiest way to test the first 3 characters of two words for a match. IE: dasf test dasg to return positive. substr(dasf, 0, 3) eq substr(dasg, 0, 3) James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Match the first 3 characters of 2 words?
perldoc -f substr would be one way. easiest is a loaded word, depends on the context and the individual... -Tom Kinzer -Original Message- From: Rod [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:19 PM To: '[EMAIL PROTECTED]' Subject: Match the first 3 characters of 2 words? What is the easiest way to test the first 3 characters of two words for a match. IE: dasf test dasg to return positive. rod. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Match the first 3 characters of 2 words?
Rod wrote: What is the easiest way to test the first 3 characters of two words for a match. IE: dasf test dasg to return positive. substr($word1, 0, 3) eq substr($word2, 0, 3) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: file path pattern matching problem.
The best way to do it; is using the standard module File::Basename. For instance use File::Basename; # This should return somefile. $file_name = basename (c:\test\abc\what\somefile.txt); # This should also return c:\test\abc\what\ $dir_name = dir (c:\test\abc\what\somefile.txt); # fileparse should returns file, directory and suffix. ($filename, $dir, $suffix) = fileparse (c:\test\abc\what\somefile.txt); Check perldocs for details. HTH Babs Ben Crane wrote: Hi all, I'm trying to split apart a filepath...e.g: c:\test\abc\what\somefile.txt The length of the filepath will never be constant... e.g: foreach $line (@Path_Filename) { chomp($line); (@Path_Breakdown) = split(/(\w+\W)(\w+\W)/, $line); } but my biggest problem is how to match a word character \w then match everything until the last \...that will comprise of the file path and the final \ onwards will be the filename incl. or excl. the file extension... I've tried to get the pattern matching to include everything including the \ but it doesn't seem to work. The closest I've gotten is: c:\test\abc\what\somefile.txt c: \test\abc\what\ somefile. txt Any ideas? Is there a pattern character that I'm missing here that allows you to match a certain character and then stop if it's the last one of it's type? Ben __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Problems forking -- fork DOSes my comp
I am learning about forks, so I tried the following code to make sure I had everything down: #! /usr/bin/perl use strict; use warnings; my $counter = 1; my $pid = 0; while ($counter 50) { if ($pid = fork) { open (FORKED, ./fork/$counter) or die(COULD NOT OPEN FORK); print FORKED $counter; close(FORKED); $SIG{CHLD} = IGNORE; } $counter++; } I figured this would write 49 files relatively quickly and that would be the end of it. Running it DOSes a 1Ghz PIII Box I have takes 20 minutes -- during which time /nothing/ else can be done, i.e. a DOS. Oddly enough, putting the limit on counter down to 5 runs in less then 0.02s. So what am I doing wrong? -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Problems forking -- fork DOSes my comp
Dan Anderson writes: I am learning about forks, so I tried the following code to make sure I had everything down: #! /usr/bin/perl use strict; use warnings; my $counter = 1; my $pid = 0; while ($counter 50) { if ($pid = fork) { open (FORKED, ./fork/$counter) or die(COULD NOT OPEN FORK); print FORKED $counter; close(FORKED); $SIG{CHLD} = IGNORE; } $counter++; } I figured this would write 49 files relatively quickly and that would be the end of it. Running it DOSes a 1Ghz PIII Box I have takes 20 minutes -- during which time /nothing/ else can be done, i.e. a DOS. Oddly enough, putting the limit on counter down to 5 runs in less then 0.02s. So what am I doing wrong? -Dan Swapping sickness! A deadly disease that consumes more memory than you have. I had the same thing happen to me last night because I had a typo in a crontab file, and instead of running a job at 1 AM, it ran the job every minute between 1 AM and 2 AM. I came in this morning to a machine that had over 150 loads on it. It took me a good 20 minutes or so to kill all the culpirts and get the poor machine back under control. Each forked task consumes memory, and you did not have enough of it to handle the load, so it started swapping. This is usually deadly if the tasks are not windows assoicated with a user-interactive task that can just sit quietly while another window's task swap in to run. In your case, all the tasks wanted to run at the same time. My crontab bug was ismilar, since the task I intended to run only once takes a long time to run and consumes a lot of mamory. Even the Apache web server only forks off a handful of tasks to service incoming requests. Big web servers with many GB or ram can form more than smaller boxes, but there is always a limit to what a box can handle. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problems forking -- fork DOSes my comp
On Dec 10, 2003, at 3:52 PM, Dan Anderson wrote: I am learning about forks, so I tried the following code to make sure I had everything down: Still don't believe me about Network Programming with Perl, eh? Did I mention that it covers forking well? laughs Basic idea of fork: if ($pid = fork()) {# TWO processes will continue from write here # in parent process } else { # in child process } #! /usr/bin/perl use strict; use warnings; my $counter = 1; my $pid = 0; while ($counter 50) { if ($pid = fork) { Again, TWO processes will go forward from this point. open (FORKED, ./fork/$counter) or die(COULD NOT OPEN FORK); print FORKED $counter; close(FORKED); $SIG{CHLD} = IGNORE; } And here's the problem, with no else, they'll do the exact same thing! Loop and fork() again. You're spawning some serious processes my friend. Use fork() when you want to do two things at once. Do one inside the if and the other in the else. Hope that helps. James $counter++; } I figured this would write 49 files relatively quickly and that would be the end of it. Running it DOSes a 1Ghz PIII Box I have takes 20 minutes -- during which time /nothing/ else can be done, i.e. a DOS. Oddly enough, putting the limit on counter down to 5 runs in less then 0.02s. So what am I doing wrong? -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problems forking -- fork DOSes my comp
On Wed, 2003-12-10 at 17:04, James Edward Gray II wrote: On Dec 10, 2003, at 3:52 PM, Dan Anderson wrote: I am learning about forks, so I tried the following code to make sure I had everything down: Still don't believe me about Network Programming with Perl, eh? Did I mention that it covers forking well? laughs LOL. Thanks for all your help. I actually put a copy on my Safari bookshelf but I have yet to start it. -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problems forking -- fork DOSes my comp
Dan Anderson wrote: I am learning about forks, so I tried the following code to make sure I had everything down: #! /usr/bin/perl use strict; use warnings; my $counter = 1; my $pid = 0; while ($counter 50) { if ($pid = fork) { open (FORKED, ./fork/$counter) or die(COULD NOT OPEN FORK); print FORKED $counter; close(FORKED); $SIG{CHLD} = IGNORE; } $counter++; } [snip] So what am I doing wrong? you are forking a lot more child than you think! what you essentially have is: start with 1 process, fork: parent process parent goes back to fork: parent parent goes back to fork: parent child child child goes back to fork: parent child child process child goes back to fork: parent parent goes back to fork: parent child child child goes back to fork: parent child ... etc the number of process looks like: 1 before fork: 2 after first fork: 4 after second fork: 8 after third fork: 16 after fourth fork. ... etc do the math for after 50 forks and you know how many process you have left in your machine and taking up all the memory and CPU time. you need to make sure the child does not go back to fork it's own child: #!/usr/bin/perl -w use strict; $SIG{CHLD} = 'IGNORE'; for(1..50){ my $pid = fork; die no resource unless(defined $pid); next if($pid); open(CHILd,$_) || die $!; print CHILD $$,\n; close(CHILD); exit; #-- kill child so it does go back } __END__ david -- s,.*,,e,y,\n,,d,y,.s,10,,s .ss.s.s...s.sss.s.ss s.s.s...s...s..s ...s.ss..s.sss..ss.sss.s s.s.s...ss.sss.s ..s..sss.s.ss.sss... ..ssss.sss.sss.s ,{4},|?{*=}_'y!'+0!$; ,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t, .y...,$~=q~=?,;^_#+?{~,,$~=~ y.!-*-/:[EMAIL PROTECTED] ().;s,;, );,g,s,s,$~s,g,y,y,%,,g,eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: First module!!! YAAAAY!!! :)
On Dec 10, 2003, at 4:39 AM, Ben Crane wrote: Just sat done and put together my FIRST MODULE congratulations. [..] I have been playing around with h2xs and getting really confused. If I understand this, the *.pm file is standalone and will work on pretty much any platform?? So if I write another one completely from scratch using this rough template it is effectively a perl module that I can distribute?? Surely it can't be THAT easy?? [..] One problem at a time, remember to breath. a. yes it is that easy to make Perl Modules b. IF you are planning on distributing them, it is best to become good friends with h2xs so that you can follow the traditional form. my pet favorite way to use h2xs to start a project that I plan to distribute is the simpler h2xs -AX package_name_here cf: http://www.wetware.com/drieux/CS/Proj/PID/#TheTypeScript What may be causing some 'issues' is that Makefile.PL and how complex does it really need to be for relatively simple projects. Start small, start simple, and build up from there. { cf perldoc ExtUtils::MakeMaker } It appears that perl5.8.1 rev of h2xs has some minor changes: [jeeves: 28:] h2xs -AX Wetware::Pid Defaulting to backwards compatibility with perl 5.8.1 If you intend this module to be compatible with earlier perl versions, please specify a minimum perl version with the -b option. Writing Wetware/Pid/Pid.pm Writing Wetware/Pid/Makefile.PL Writing Wetware/Pid/README Writing Wetware/Pid/t/1.t Writing Wetware/Pid/Changes Writing Wetware/Pid/MANIFEST [jeeves: 29:] So now you start with the 'first test' in the t/ to help you start growing out your basic static testing. It will also gin up that Changes File, which will help keep your 'when and why' notes on what changed. { also best to keep track of who filed which bug on what...} The MANIFEST will help keep track of all of the files. The README is important as it covers everything not covered elsewheres - and if you do not yet have a default license file that you would include it has a prototype. So that offers you the base Frame Work to work with. NOW comes the 'big uglies' about the design philosophy issues - Unless you are Lincoln Stein, do not try to make your module BOTH OO-ish and Procedural, it can be done - but pick one or the other. I come from the 'put the POD in a Foo.pod file' school, others come from the 'interleave pod and code', while some are true believers of the 'pod at the end'. But think about how other persons pod has helped you, do the same. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: removing duplicate lines
Andrew Gaffney wrote: John W. Krahn wrote: Whenever you want unique values think hash. Well, it would have been weird to have a hash with keys named 'NET USE F: SKYLINE\\SKYLINEF\r\n'. No. It is not at all wierd to use hash for any of the puroses for which it is well-suited. Among of those purposes are ensuring unique .ness and testing existence. 1-valued hashes are extremely efficient engines fr both my $paths_seen = {}; foreach $drive (keys drives) { my $map_command = $drive{$_}; next if $paths_seen-{$map_command); assign_drive($map_command); $paths_seen-{$map_command) = 1; } The above assumes that you are willing to make brute-force assumptions about which mapping to a particular share is the appropriate one. If there are factors you wish to weigh in chosing which mapping to keep, you would want to call some resolving function when an element is found rather than simply next-ing. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: adding path to $PATH
On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote: Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 let me see IF I get your idea. I have a command say add_path so that you could do something like vladimir: 70:] echo $PATH /usr/local/bin:/usr/X/bin:/usr/bin vladimir: 71:] add_path vladimir: 72:] echo $PATH /happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin vladimir: 73:] that's not really going to happen, since you want to change the environment of the currently running process by having a sub-process 'signal it'... What is relatively 'easy' to do, is to create a sub_shell that will run with a different set of environmental variables. vladimir: 89:] echo $BOB BOB: Undefined variable vladimir: 90:] perl add_path vladimir% echo $BOB my bob here vladimir% exit vladimir% vladimir: 91:] sed 's/^/### /' add_path ### #!/usr/bin/perl -w ### use strict; ### ### my $path = '/happy/place/here'; ### $ENV{PATH} = $path . : . $ENV{PATH} ; ### $ENV{BOB} = my bob here; ### exec(/usr/bin/csh -f); vladimir: 92:] This is a trick I use when I am trying to run some 'alternative environment' than my default home shell. But as you notice, it is using 'exec()' to replace the script space a csh that will not source my .login and .cshrc file. It also means that I have a 'double exit' case, where I have to exit out of the current shell and then out of my 'default login shell'. Remember it is easier to change the behavior of a sub_shell than it is to try to signal upwards to some calling shell. Try not to go that way... ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
-e with single quotes
Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? TIA Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: -e with single quotes
Guessing here but maybe you don't want to use *Perl's* escape, but instead use your *shell's* escape. Whatchu running from? -Tom Kinzer -Original Message- From: Dan Muey [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 3:05 PM To: beginners Subject: -e with single quotes Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? TIA Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: adding path to $PATH
drieux writes: On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote: Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 let me see IF I get your idea. I have a command say add_path so that you could do something like vladimir: 70:] echo $PATH /usr/local/bin:/usr/X/bin:/usr/bin vladimir: 71:] add_path vladimir: 72:] echo $PATH /happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin vladimir: 73:] that's not really going to happen, since you want to change the environment of the currently running process by having a sub-process 'signal it'... I am not a c-shell guy, but in then Bourne shell, or in bash, you could accomplish what you want in a similar fashion thus: # instead of add_path being called directly, you can do this: export PATH=`add_path`:$PATH The back-quotes perform what lispers call a splice macro. The value that is returned on add_path's stdout replaces the text or `add_path` so that it does what you want. So add_path might look something like this: #!/bin/bash # add_path -- return a path to add to PATH echo /some/unusual/path:/another/one:/and/so/forth I know there is a similar construct in csh, but I do not remember what it is. I hope this is at least some help. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: -e with single quotes
Hmmm, that's a tough one. Normally you can still escape a single quote inside single quotes, but maybe in this case it would be just easier to do a: C:\ perl print 'joe\'s mama'; ^Z (for windows anyway) -Original Message- From: Dan Muey [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 3:05 PM To: beginners Subject: -e with single quotes Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? TIA Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: -e with single quotes
From: Dan Muey [EMAIL PROTECTED] I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? WHAT IS YOUR OPERATING SYSTEM AND/OR SHELL ??? This is not really a Perl question ... you need your shell/command prompt to do something, not Perl. If you use Windows and its cmd.exe/command.com you have to use doublequotes. Fullstop. perl -e print qq{joe's mama\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/ http://learn.perl.org/first-response
RE: adding path to $PATH
in korn it would be: export PATH=$(add_path):$PATH -Original Message- From: Robert Brown [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 3:20 PM To: drieux Cc: Perl Perl Subject: Re: adding path to $PATH drieux writes: On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote: Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 let me see IF I get your idea. I have a command say add_path so that you could do something like vladimir: 70:] echo $PATH /usr/local/bin:/usr/X/bin:/usr/bin vladimir: 71:] add_path vladimir: 72:] echo $PATH /happy/place/here:/usr/local/bin:/usr/X/bin:/usr/bin vladimir: 73:] that's not really going to happen, since you want to change the environment of the currently running process by having a sub-process 'signal it'... I am not a c-shell guy, but in then Bourne shell, or in bash, you could accomplish what you want in a similar fashion thus: # instead of add_path being called directly, you can do this: export PATH=`add_path`:$PATH The back-quotes perform what lispers call a splice macro. The value that is returned on add_path's stdout replaces the text or `add_path` so that it does what you want. So add_path might look something like this: #!/bin/bash # add_path -- return a path to add to PATH echo /some/unusual/path:/another/one:/and/so/forth I know there is a similar construct in csh, but I do not remember what it is. I hope this is at least some help. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I set up bidirectional pipes over a network connection?
On Dec 10, 2003, at 5:54 AM, Dan Anderson wrote: [..] Actually, that's a good idea too. Thanks for your suggestions! -Dan while I like the NFS idea, you might want to look into the idea of a SAN/NAS device that is already hardened with fail over CPU's, etc, etc, etc... then as long as you keep all of your hosts and you SAN/NAS on the same ethernet switch you have a very low probability of failure. IF the 'in hardware' solution doesn't fly, clearly start at least with walking through POE, and specifically the Cook Book: http://poe.perl.org/?POE_Cookbook it will save you some time in getting something up and running easily. While I am not familiar with Network Programming with Perl http://modperl.com:9000/perl_networking/sample/toc.html I trust the Author. Especially IF this is your first time into hard corp network programming, and you are more interested in getting down and dirty with learning, and not merely 'solving a specific' problem. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: -e with single quotes
Guessing here but maybe you don't want to use *Perl's* escape, but instead use your *shell's* escape. Oh yeah, duh. I thought \ was my shell's escape character(bash) Whatchu running from? Nothing, just want to be able to use single quotes :) -Tom Kinzer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Recommendations?
Derek Brinson wrote: Where might I find reference (conceptual) stuff about how to launch a JAVA app via CGI (or vice versa)? Still working it out, but it appears that I may need to get some CGI variables into a JAVA App. Surely this is too difficult to be encapsulated in a website or two? -d Is this a Perl question? If so, can you give us more specifics on what you are trying to achieve, and what part you see Pel playing in this? Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: -e with single quotes
Dan Muey [EMAIL PROTECTED] wrote: Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? I've had this problem too, specifically when trying to run perl inside a Korn shell script. The following, though, will work for you on Win32 or *nix systems: $ perl -e '$q=chr(0x27);print joe${q}s mama' joe's mama -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: -e with single quotes
Dan Muey [EMAIL PROTECTED] wrote: Hello group. I'm tryign to do a perl -e '' command and am wondering if it is possible to do single quotes inside the single quotes. IE perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. Is there a way to use a single quote inside a single quoted -e command? Using a different character would just cause the same problem but with different characters right? I've had this problem too, specifically when trying to run perl inside a Korn shell script. The following, though, will work for you on Win32 or *nix systems: $ perl -e '$q=chr(0x27);print joe${q}s mama' joe's mama Beautiful Jeff, Beuatifull. I'll give that spin and see how she does. Thanks again! -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: -e with single quotes
On Wed, Dec 10, 2003 at 05:05:26PM -0600, Dan Muey wrote: perl -e 'print joe's mama;' Obvo=iously won't work perl -e 'print joe\'s mama;' And any other versions of \\' all fail. As you were told, this is a question of your shell. If you are using a bourne shell (zsh, bash, ksh, etc...) try this: perl -e 'print joe'\''s mama;' ^ ^ ^^^ 1 2 345 The trick is: 1. start single quoted string 2. end single quoted string 3. escaped single quote 4. start single quoted string 5. end single quoted string -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sorter script with *MANY* unique records
Robert Brown wrote: But how do they compare when the heash is too big to fit in main memory? If the has starts swapping, you loose! I do not know, however, whether using a database based hash would be faster or slower than the sort -u approach. It would make for an interesting test. Try sorting a file with over 3E8 unique integers, or maybe just a file with 256 byte records, and enough unique records to not fit in memory. I would say here that at least part of the issue is designing around the need for swollen data sets. It is true that hashes get their speed at the cost of memory allocations, since the structures perform best when sparsely populated. There will cetainly be cases where the sheer immensity of a data set may call for a more memory-efficient storage structure, at the cost of vastly increased [O(log n) for inserts and deletions,O( n log n) for sorts versus O(1) for hash operations, with occasioanl overhead from resizing and re-hashing] process times. I tend to think that, were I trying to handle voluminous quantities of data, I might want to call a C-coded B-Tree for storage purposes. I see these kind of tasks as more exception cases calling for special handling than a standard to dictate normal coding practices, though. Most CPUs in use average about 99% idle time, at least on the computers [some running up to 20 open windows] on which I have checked these stats. To me, the more important issues in normal practice have to do with comprehensibility, and thus maintainability, than with technical performance comparisons. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sorter script with *MANY* unique records
R. Joseph Newton writes: Most CPUs in use average about 99% idle time, at least on the computers [some running up to 20 open windows] on which I have checked these stats. To me, the more important issues in normal practice have to do with comprehensibility, and thus maintainability, than with technical performance comparisons. That is a very good point, and one that needs to be considered more often! My question was not for the usual case, but the unusual one. I was just wondering if anyone on the list had done such a comparison before and could share the results of the experiment. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
splitting a string
Hi: I want to split the string 0.0.0.0.1.10.1.30.1.10.1.30.1 into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1 any suggestions? TIA ravi __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sorter script [was: Frustrated newbie question]
On Dec 9, 2003, at 4:20 PM, R. Joseph Newton wrote: [..] To me hashes are like sausage to a carnivore--I love the end product, but have no desire to look too closely at the process. [..] first the last, the schwartzian transformation I included was from the perldoc -q sort as a way of noting that there are some interesting things that can be done, if done well, in memory. So on top of the usual 'portability' sets of issues there is also the problem that some 'sort' utilities will 'fault' to an I/O event to write out intermediary stage results, so as to save on memory usage. The PPT version of sort does not take a -T dir option to allow one to fan out the intermediary stages, nor does it offer a -ykmem option... caveat emptor. Warning: Serious GEEKING... I like your idea of 'shape()' - in the abstract - as a way of 'visualizing' the problem. Since that does point back to the 'design elements' of a well done 'database solution'. { for me, many of the 'implementation details' of DataBaseFoo, should be handled, like hashes, as things we do, but prefer not to talk about in polite society. } The problem with 'aesthetics' - my 'ugly sort' kvetch, is that at times a bit of brute force is 'good enough' - and can be better than the most 'elegant' of looking algorithms. One case in particular that left scars was what technically was an 'elegant' SQL query a co-worker had constructed. Since it seemed to be simpler. The problem was that it meant a series of interesting join statements that bogged the database engine down. { some of that was due to bad implementation on the db engine. } Rather than taking the 'less elegant' bute force approach of two 'get foo' things that would dump more bits on the wire, but less weight on the db engine, and the post processing was done on 'cheaper' support servers. So while a given algorithm may map out as O(foo_val) in the logical analysis, depending upon what else is in play, it may have an impact that is disproportionate. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: splitting a string
On Dec 10, 2003, at 4:49 PM, Ravi Malghan wrote: Hi: I want to split the string 0.0.0.0.1.10.1.30.1.10.1.30.1 into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1 any suggestions? yes, get better data. a part of the problem you have is the that you could do this with a regEx my $input = '0.0.0.0.111.10.1.30.1.10.1.30.1 '; my $dot_quad = qr/\d+\.\d+\.\d+\.\d+/; my ($im, $jm , $km, $mm ) = $input =~ /($dot_quad)\.(\d+)\.($dot_quad)\.($dot_quad)/; cf perldoc perlre ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: splitting a string
Ravi Malghan wrote: Hi: I want to split the string 0.0.0.0.1.10.1.30.1.10.1.30.1 into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1 any suggestions? TIA ravi Here is one approach: #!perl -w use strict $_ = '0.0.0.0.1.10.1.30.1.10.1.30.1'; my @MyWorka = (); @MyWorka = split(/\./, $_); my @MyWorkb = (); my @MyWorkc = (); my @MyWorkd = (); @MyWorkb = splice(@MyWorka,-4,4); @MyWorkc = splice(@MyWorka,-4,4); @MyWorkd = splice(@MyWorka,-1,1); printf %-s, %-s, %-s, %-s\n, join('.', @MyWorka), @MyWorkd, join('.', @MyWorkc), join('.', @MyWorkb); Output: 0.0.0.0, 1, 10.1.30.1, 10.1.30.1 Wags ;) __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern Match
Robert Brown wrote: Casey West writes: Sorry again for my confusing way of expressing myself. Although I wrote my example in C, that was because I am a novice perl programmer, but an experienced C programmer, so I expressed my algorithm in C. The idea was to compare the execution effeciency of a perl regular expression approach to a less syntacticly compact algorithmic approach using loops and conditionals, still written in perl, to edit the string. I just used C so you all would not beat me up over perl syntax details instead of answering the real question. I think I see the question more clearly here. Actually, I would say that you are better off using Perl built-ins, particularly in the case of sorts and similar problems. What you want to bear in mind is that Perl is written largely in C, and the builders make very good use of the optimizations available in that language in implementing the built-in functions. The Perl sort is lightning fast. Regex solutions are as fast as problems of their level of complexity can be implemented. If that sounds vague, it's because the Perl regex is so well optimized. Say you do a regex that asks only for the right string at the base: if ($string =~ /^Target/). The Perl regex will do only enough work to evaluate the question posed in the regex. On the other and, if you do my $string =~ /Total (\d[12dg5]{2,5})+\(.*)\/g; you might expect a somewhat heavier processing load. Of course, if information structured with such parameters is your pot of gold, it may be worth the expense, because it will extract it [probably--I didn't test the second regex]. Clearly, the more complicated your regex is in its structure, the more processing will be involved in using it. This is why, for instance, list members often caution against trimming a string in a single statement. $string =~ s/^\s+(.*)\s+$/$1/; is much more costly than: $string =~ s/^\s+//; $string =~ /\s+$//; When used consciously, with at least a general awareness of the processing load being invoked, regexes can do some really incredible things. The problem with rolling your own in Perl is the overhead of Perl's magic variables. Although Perl scalars have very useful features, each scalar does require structures to support them. So when you try to compete with built-in functionality, operating at full, optimized C-language implementation speed, you are carrying a lot of baggage into the race. You will probably lose, no matter how efficient your code. Perl actually does call for a different coding approach than C. Would any C coder try to roll their own stdio? It seems like that would be a pretty rare occurence. the standard library is part of the language, and C-coders make use of it. The core and standard modules are likewise a part of the Perl language as a whole. It can't hurt to do some experimenting on your own, and to compare performance. Just keep an open mind about it. Since it sound like you have a considerable investment in your C work, you might also consider packaging some of it for use in Perl. I'm not recommending embedded code here, so much as looking for Perl interfaces to compiiled C object files that your Perl programs can call on for specialized and highly optimized jobs. Except to point you in that general direction, I can't offer much help. I think there are others on the list, though, who can point you to more depth material on integration. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
installing DBD::mysql
Hi everybody: I´m trying to install DBD:mysql from CPAN and i get the next message Warning: prerequisite DBI failed to load: Can't locate DBI.pm in @INC (@INC contains: /usr/perl5/5.6 .1/lib/sun4-solaris-64int /usr/perl5/5.6.1/lib /usr/perl5/site_perl/5.6.1/sun4-solaris-64int /usr/pe rl5/site_perl/5.6.1 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.6.1/sun4-solaris-64int /usr/perl5/ vendor_perl/5.6.1 /usr/perl5/vendor_perl .) at (eval 4) line 3. Looks good Note (probably harmless): No library found for -lgz Can't locate DBI/DBD.pm in @INC (@INC contains: /usr/perl5/5.6.1/lib/sun4-solaris-64int /usr/perl5/5 .6.1/lib /usr/perl5/site_perl/5.6.1/sun4-solaris-64int /usr/perl5/site_perl/5.6.1 /usr/perl5/site_pe rl /usr/perl5/vendor_perl/5.6.1/sun4-solaris-64int /usr/perl5/vendor_perl/5.6.1 /usr/perl5/vendor_pe rl .) at Makefile.PL line 294. DBI was installed successfully with CPAN, but DBD. Does anyone have an idea what´s happen with perl an CPAN? Thanks Carlos Alberto De Jesus Velasquez Universidad Marista-La Salle Guadalajara
simple link checker...
Hi All, Can someone suggest a really simple CPAN module that will validate links on a website. I need something like linklint - except that it needs to be on very very simple, and i'm sure there is a CPAN module out there i can use (i just can't seem to find a good one)... All i need to do is: * Validate the links on pages on a particular site The reason i don't want to use linklint is that it has some hardcoded output formats, and i need to output to a very specific html output format, so a perl module that just traversed a site and returned the results (rather than save them to a file) would be idea. simran. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sorter script with *MANY* unique records
On Dec 10, 2003, at 4:02 PM, R. Joseph Newton wrote: [..] Most CPUs in use average about 99% idle time, at least on the computers [some running up to 20 open windows] on which I have checked these stats. Not wishing to get us bogged down in a convention of the IEEE Transactions of Distributed Processing are you talking here in terms of the average 'desk top' unit that most persons have access to? Back End headless servers in dedicated database services mode? yada-yada-yada... { forgive me, I was traumatized by major data center issues at a formative age, where optimizing CPU utilization on crays was an Imperative... But my therapist says I'm getting better...8-} To me, the more important issues in normal practice have to do with comprehensibility, and thus maintainability, than with technical performance comparisons. Is that 'normal' as in 'bell curve shaped' or as in 'normalized data', as in DB speak? 8-) I think a part of the underlying set of questions here are when is it time to move one's data sets out of the simpler perl tiehash with a generic DB_FILE and off into a 'real database' - such as Postgres, as Randall Schwartz recently noted some of the newer benchmark numbers. The simplest answer is when the DB portion of the process is the log_jam Which then takes us back into what I wish to underscore in R. Joseph's point, IF one has written modular, and maintainable, DB interface code Then one simply opts to change the guts on the inside of a Module. If one has built it in such a way that one already is using a 'network query' interface, where one has already abstracted the database semantics, one can do this without changing anything on the 'client side' of that code. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help needed on perl wrappers
Pandey Rajeev-A19514 wrote: Hi, I was interested in formatted display on screen. I can display ONE text paragraph in any part of the screen with Text::wrap. My question was how to adjust MANY such independent paragraphs in one screen (exactly in a newspaper format where you have 8-10 columns of news items on a single page). I wanted to know is there something like Text::wrap which can do this. Or Text::wrap can handle only one paragraph. If nothing like that exists then I might have to give up Text::wrap and use my own logic to adjust it. Moreover, I also wanted to use Term::Size to adjust the text with changing screen size. Is there any convenient way to do this ? I was looking for readymade stuff. Please suggest. Regards Rajeev -Original Message- From: Tom Kinzer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 12:05 PM To: [EMAIL PROTECTED] Subject: RE: Help needed on perl wrappers I'm trying to figure out WHY you would ever want to create what you are asking for. Why-- is a good question here, because there may be a way to get to the real goal instead of creating this. For instance if it's just going into an HTML document, a table of course, would be easier. Just an example, so WHY are you wanting to do this? If this is really want you want, then: Do you really want a ragged left on the right column? Do you really want to use tabs? I'm thinking spaces would be easier to deal with for this problem and could buy you a justified left margin on the right column. More info please. -Tom Kinzer -Original Message- From: Pandey Rajeev-A19514 [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 09, 2003 8:16 PM To: '[EMAIL PROTECTED]' Subject: Help needed on perl wrappers Hi, I have a text that I read from a file. I want to display the text on the screen in a column in a newspaper style. I do it like this $initial_tab = \t\t; $subsequent_tab = \t\t; print wrap($initial_tab, $subsequent_tab, @text1); print fill($initial_tab, $subsequent_tab, @text1); It will print like this ... I am a boy and I go to school everyday. I have to do a lot of homework and I dont get time to play these days. But if I have more than one independent text i.e. @text2, @text3 to be displayed in different columns, then what shall i do. I want something like this ... I am a boy and I go to schoolShe is a girl and she also goes everyday. I have to do a lot ofto school. I do all her homework homework and I dont get time and she gets plenty of time to to play these days play. Is there any mechanism to achieve this ? Best Regards Rajeev Hi Rajeev, What you are asking for does seem a little bit funky. Please be aware that this type of formatting works only on even-width screens. Tabs are also very importable, since different applications may render them in different ways. That being said, I can see two routes: 1. Perl does provide formats perldoc -f format that can help align your output for even-width renderings. 2. Try the printf and sprintf functions. Once you get accustomed to the syntax [inherited from C] of their format strings and escapes, you may find them very handy. You can specify the width, alignment, and space or zero-padding, of you output very succinctly using these functions: perldoc -f printf perldoc -f sprintf Overall, I might recommend using or generating HTML for a job like this. This is the sort of work that markup was built for. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: dbmopen problem
Well, I guess I'll reply since nobody else has... Problem is I still have no clue what's wrong here... :^) Surely somebody here can offer a hint? Please? :^) j On Mon, 2003-12-08 at 01:06, Joel Newkirk wrote: I've run into a problem. I have been working on a webmin module that, among other things, maintains a dbm file of regular expressions. One subroutine is passed a string, and if any of the regular expressions matches, it returns the associated explanation text. I can read and write this dbm with no issues. Now I'm working on a console command to offer the same functionality (only needing to read the rules, not write) using the same dbm. I've used precisely the same subroutine as in the webmin version, but whenever I reach: dbmopen (%PLRULES, /var/szs/rules.dbm, undef) or die $!; I die, with No such file or directory. Absolute path, world-readable files owned by root, precisely the same statement in each, the webmin CGI version and the console version. The webmin CGI is NOT runnning when I try this from the console, and I'm root when trying. What am I doing wrong?? j -- Not all those who wander are lost. - JRR Tolkien -- Not all those who wander are lost. - JRR Tolkien -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: First module!!! YAAAAY!!! :)
Ben Crane wrote: Hi all, Just sat done and put together my FIRST MODULE I went through an edited/modifyed text::parsewords and after lots of testing, editing and playing around with...I got it to work! I didn't realize it could be THIS easy! I have been playing around with h2xs and getting really confused. If I understand this, the *.pm file is standalone and will work on pretty much any platform?? So if I write another one completely from scratch using this rough template it is effectively a perl module that I can distribute?? Surely it can't be THAT easy?? Sure can, and it is. Still, there is complication that will arise once you start building modules for real-world purposes. One thing you will probably find is that classes [packages] may be more suitable for representing systems of processes than procedural code. Still, even procedural modules can be very useful for storing commonly-used functionality. Have fun. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: adding path to $PATH
On Dec 10, 2003, at 3:06 PM, drieux wrote: On Dec 9, 2003, at 10:09 PM, Pablo Cusnir wrote: Is there a way using Perl to add to the environment variable PATH a new path, and that addition will be valid after the script is ran and not only for the script's scope. I'm working in cshell in Solaris 5.8 [..] Robert, Tom, thank you for the advice, and the good intentions, but forgive me if I go back over what I posted to demonstrate a solution, complete with executing it to perchance go back over a series of basic issues. The critical part of the OP's query is valid after the script is ran and not only for the script's scope Unfortunately this is almost FAQ country, since almost every 'scripter' notices that it would be cooler IF they could do something like that. But they do not always think about which part of the process they are really trying to 'fix'. Both of you saved the 'demonstration' portion of my response to the OP, where I tried to illustrate the idea of what the OP seems to have been asking. But without actually noting the portion of the live run code: vladimir: 89:] echo $BOB BOB: Undefined variable vladimir: 90:] perl add_path vladimir% echo $BOB my bob here vladimir% the prompt shifts from the 'cool' csh style defined in my .login as set prompt=`Hostname`: \!:] back to a 'system default style' as vladimir% that occurred because the perl code: vladimir: 91:] sed 's/^/### /' add_path ### #!/usr/bin/perl -w ### use strict; ### ### my $path = '/happy/place/here'; ### $ENV{PATH} = $path . : . $ENV{PATH} ; ### $ENV{BOB} = my bob here; ### exec(/usr/bin/csh -f); vladimir: 92:] really does exec() a csh with the -f flag, so that the newly spawned shell will NOT go back and resource my .login and .cshrc files, so that the '$ENV{PATH} = $path . : . $ENV{PATH} ;' will pre-pend the value for all sub-sequent shells. { note, yes, we could expand that code to a. test that $path existed in the $ENV{PATH} b. if not then to update the .login/.cshrc as appropriate c. then exec ourselves } The point of this drill is three fold: a. IF the OP wanted to simply edit their .login and/or .cshrc file to fix the PATH line, then they have already been informed of that. { someone even was polite enough to point to one of the canonical FAQ's about this. } b. the problem of trying to execute a command in a shell that is, by it's very nature, being executed in a 'sub_shell' will be HARD PRESSED to go back and 'fix' the environment of the spawning shell irregardless of the nature of the coding language used. { since technically the 'environment' is part of the process space information, there is merely the issue of gaining access to that information and bit twiddling it. Not something I will advocate while sober. } c. we all need to work on our reading and writing skills. The perl add_path I hacked is derived from a much older piece of ksh that I used: vladimir: 62:] sed 's/^/### /' goMars ### #!/bin/ksh ### ### # ### # a way to play around in the Happy Mars Land Game ### # ### ### CommonDefFile=${HOME}/etc/drieuxTool.dfn ### ### if [ -f ${CommonDefFile} ] ### then ### . ${CommonDefFile} ### else ### echo unable to find ${CommonDefFile} ### exit ### fi ### ### PS=HappyMars ### export PS ### ENV=${HOME}/.mars.kshrc ### export ENV ### ### ksh ### ### exit vladimir: 63:] This way I could keep my default 'csh' login shell, clean from all of that Foo CommonDefFile Definitions as well as the .mars.kshrc set of ENV values, while still giving me a 'work around' that would let me flop into mars for doing certain types of work. The reason I did not want to gobbledeGook up my lovely .cshrc/.login file is that it is unpleasantly bloated enough as it is so that it solves on the fly which set of *nix ThingiePoos are in play based upon the underlying type/version of *nix the file is invoked on... { don't ask. MORE deep seated unresolved cross platform compatibility issues. Not to mention odd divergences within the linux sub-cult of the *nix cults... } Any Questions? ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: simple link checker...
Simran wrote: Hi All, Can someone suggest a really simple CPAN module that will validate links on a website. I need something like linklint - except that it needs to be on very very simple, and i'm sure there is a CPAN module out there i can use (i just can't seem to find a good one)... All i need to do is: * Validate the links on pages on a particular site The reason i don't want to use linklint is that it has some hardcoded output formats, and i need to output to a very specific html output format, so a perl module that just traversed a site and returned the results (rather than save them to a file) would be idea. HTML::LinkExtor can probably help you here. a simple demo: #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTML::LinkExtor; #-- #-- i am being very lazy in the demo #-- you should really localize it in a block #-- local $/; my $p = HTML::LinkExtor-new(\hrefs)-parse(DATA); sub hrefs{ my($tag,@links) = @_; return unless($tag =~ /^a$/i); my $p = LWP::UserAgent-new-request( HTTP::Request-new(GET = $links[1])); print $p-is_success ? GOOD: $links[1] : $p-status_line . $links[1], \n; } __DATA__ html a href=http://www.ibm.com; br a href=http://www.perldoc.com; a href=http://www.not-found99.com; /html __END__ prints: GOOD: http://www.hotmail.com GOOD: http://www.perldoc.com 500 Can't connect to www.not-found99.com:80 (Bad hostname 'www.not-found99.com') http://www.not-found99.com i believe the HTML::LinkExtor has a better and more complete example so you should check it out: perldoc HTML::LinkExtor david -- s,.*,,e,y,\n,,d,y,.s,10,,s .ss.s.s...s.sss.s.ss s.s.s...s...s..s ...s.ss..s.sss..ss.sss.s s.s.s...ss.sss.s ..s..sss.s.ss.sss... ..ssss.sss.sss.s ,{4},|?{*=}_'y!'+0!$; ,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t, .y...,$~=q~=?,;^_#+?{~,,$~=~ y.!-*-/:[EMAIL PROTECTED] ().;s,;, );,g,s,s,$~s,g,y,y,%,,g,eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: splitting a string
For those of you that are interested, I benchmarked a few of the suggestions. Drieux is by a significant margin the winner speed-wise. What I did was split the scalar into an array and then define the four variables by join()ing the result using an array slice instead of making a new array. Running this code, cutting out the print statements: ### use strict; use warnings; use Benchmark; my $mine = timethese(100, {Mine = sub{ my $string = '0.0.0.0.1.10.1.30.1.10.1.30.1'; my @nums = split(/\./,$string); my $first = join('.',@nums[0..3]); my $second = $nums[4]; my $third = join('.',@nums[5..8]); my $fourth = join('.',@nums[9..12]); },Drieux = sub{ my $input = '0.0.0.0.111.10.1.30.1.10.1.30.1 '; my $dot_quad = qr/\d+\.\d+\.\d+\.\d+/; my ($im, $jm , $km, $mm ) = $input =~ /($dot_quad)\.(\d+)\.($dot_quad)\.($dot_quad)/; },Wags = sub{ $_ = '0.0.0.0.1.10.1.30.1.10.1.30.1'; my @MyWorka = (); @MyWorka = split(/\./, $_); my @MyWorkb = (); my @MyWorkc = (); my @MyWorkd = (); @MyWorkb = splice(@MyWorka,-4,4); @MyWorkc = splice(@MyWorka,-4,4); @MyWorkd = splice(@MyWorka,-1,1); }}); # Gave me this result: Benchmark: timing 100 iterations of Drieux, Mine, Wags... Drieux: 9 wallclock secs ( 8.16 usr + 0.00 sys = 8.16 CPU) @ 122518.99/s (n=100) Mine: 12 wallclock secs (11.76 usr + 0.00 sys = 11.76 CPU) @ 85055.71/s (n=100) Wags: 14 wallclock secs (14.53 usr + 0.00 sys = 14.53 CPU) @ 68818.39/s (n=100) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problems forking -- fork DOSes my comp
On Dec 10, 2003, at 4:52 PM, Dan Anderson wrote: I am learning about forks, so I tried the following code to make sure I had everything down: #! /usr/bin/perl use strict; use warnings; my $counter = 1; my $pid = 0; while ($counter 50) { if ($pid = fork) { open (FORKED, ./fork/$counter) or die(COULD NOT OPEN FORK); print FORKED $counter; close(FORKED); $SIG{CHLD} = IGNORE; } $counter++; } Two major problems: o You are not closing your children when they are done with their tasks, meaning that they re-enter the while() loop and fork new children themselves. (this is why you fork-bombed your box) o You are doing the work in the parent, not in the child you want something like this: $SIG{CHLD} = IGNORE; for my $counter(0...50) { my $pid = fork(); if($pid == 0) { # child open FORKED, ./fork/$counter or die(COULD NOT OPEN ./fork/$counter); print FORKED $counter; close(FORKED); exit; # critical to exit here, else this child will spawn new children itself } } // George Schlossnagle // Postal Engine -- http://www.postalengine.com/ // Ecelerity: fastest MTA on earth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response