Sorting files in a directory, without using any OS specific command, ordered by modified timestamp
Hi all, The following perl program, for sorting files in a directory, without using any OS specific command, ordered by modified timestamp is not working. Please help. *Perl Program* #!perl.exe use strict; use warnings; my $directory_name; print This program print the files in ascending order of timestamp.\n; print \n; ## print Enter directory name : ; ## ## $directory_name = STDIN; ## chomp $directory_name; $directory_name = /tmp/test/; die ERROR : $directory_name is NOT a directory, $!\n if ( ! -d $directory_name ); my @files_in_directory; opendir ( DIR1, $directory_name ) or die Unable to open the directory $directory_name : $!\n; my $filename; while ( defined ( $filename = readdir ( DIR1 ) ) ) { next if ( ( $filename eq . ) or ( $filename eq .. ) ); push ( @files_in_directory, $filename ); } closedir ( DIR1 ); print Unsorted listing of files in $directory_name directory are as follows :-\n; my $i; foreach $i ( @files_in_directory ) { print $i . \n; # my ( $atime, $mtime, $ctime ); #( undef, undef, undef, undef, undef, undef, undef, undef, $atime, $mtime, $ctime, undef, undef ) = ( stat($i) ); #print atime=[$atime],mtime=[$mtime],ctime=[$ctime]\n; # print atime=[ . (stat($i))[8] . ],mtime=[ . (stat($i))[9] . ],ctime=[ . (stat($i))[10] . ]\n; } print \n; my @sorted_files_in_directory; @sorted_files_in_directory = sort { (stat($a))[9] = (stat($b))[9] } @files_in_directory; print Sorted listing of files in $directory_name directory are as follows :-\n; my $j; foreach $j ( @files_in_directory ) { print $j . \n; } print \n; *Directory Listing* # ls -ltra /tmp/test/ | grep -v ^total | grep -v ^d -rw-r--r-- 1 root root 131699 Jan 12 2009 install.log.syslog -rw-r--r-- 1 root root 59020 Jan 12 2009 install.log -rw-r--r-- 1 root root 1267 Jan 12 2009 anaconda-ks.cfg -rwxr-xr-x 1 root root 1574 May 21 2009 sys_bkp.pl -rw--- 1 root root 17673 Jun 2 2009 mbox -rw--- 1 root root 2630 Aug 17 2009 nohup.out1 -rw--- 1 root root 2630 Aug 17 2009 nohup.out2 -rw-r--r-- 1 root root 1569 Dec 1 11:58 sort.pl *Perl Program Output* # perl /root/print_files_sort.pl This program print the files in ascending order of timestamp. Unsorted listing of files in /tmp/test/ directory are as follows :- sys_bkp.pl nohup.out2 nohup.out1 anaconda-ks.cfg install.log sort.pl mbox install.log.syslog Sorted listing of files in /tmp/test/ directory are as follows :- sys_bkp.pl nohup.out2 nohup.out1 anaconda-ks.cfg install.log sort.pl mbox install.log.syslog # Thanks Regards, Amit Saxena
Monitoring ssh connectivity to a server using perl !
Hi all, What's the best way to monitor ssh connectivity, and not just ssh port availability, to a server using perl assuming following constraints ? I tried for Net::SSH but public private key is not allowed. I tried for Net::SSH::Perl etc but these are not built in perl distribution (active perl on windows or part of perl distribution of linux / solaris). Can we do it via IO::Socket::INET ? Thanks Regards, Amit Saxena
Re: Monitoring ssh connectivity to a server using perl !
On Tue, Nov 23, 2010 at 10:09 PM, shawn wilson ag4ve...@gmail.com wrote: Well, each new ssh connection should spawn a new process so you could look at it from that end. More technically, you could look into netstat or lsof modules. On Nov 23, 2010 11:31 AM, Amit Saxena learn.tech...@gmail.com wrote: Hi all, What's the best way to monitor ssh connectivity, and not just ssh port availability, to a server using perl assuming following constraints ? I tried for Net::SSH but public private key is not allowed. I tried for Net::SSH::Perl etc but these are not built in perl distribution (active perl on windows or part of perl distribution of linux / solaris). Can we do it via IO::Socket::INET ? Thanks Regards, Amit Saxena Thanks Shawn for the reply. Actually my requirement, to be specific, is as follows. The script will be executed in periodic fashion from a *nix server and the script will initiate a ssh connection to itself using perl. This is to confirm that the ssh service is running and there is no issue in getting a new and authenticated ssh session when clients will connect to the server via ssh externally. Please suggest. Thanks Regards, Amit Saxena
Re: [PBML] Re: Monitoring ssh connectivity to a server using perl !
On Wed, Nov 24, 2010 at 1:19 AM, Joe Pepersack j...@pepersack.net wrote: Why not just call the ssh client and run a command on the remote host? I'd set up a passwordless key to a restricted account for security, but I'm paranoid. open LOG, '', '/path/to/logfile' or die Can't open log file\n; foreach my $target ( qw[ u...@host1 u...@host2 u...@localhost ] ) { my $uptime = `/usr/bin/ssh -i /path/to/private_key $target uptime`; my $now = localtime; if ( defined($uptime) ) { print LOG $now\tSSH is up on $target\n; } else { print LOG $now\tSSH is down on $target\n; } } On 11/23/2010 11:43 AM, Amit Saxena wrote: On Tue, Nov 23, 2010 at 10:09 PM, shawn wilson ag4ve...@gmail.comag4ve.us%40gmail.com mailto:ag4ve.us%40gmail.com ag4ve.us%2540gmail.com wrote: Well, each new ssh connection should spawn a new process so you could look at it from that end. More technically, you could look into netstat or lsof modules. On Nov 23, 2010 11:31 AM, Amit Saxena learn.tech...@gmail.comlearn.tech123%40gmail.com mailto:learn.tech123%40gmail.com learn.tech123%2540gmail.com wrote: Hi all, What's the best way to monitor ssh connectivity, and not just ssh port availability, to a server using perl assuming following constraints ? I tried for Net::SSH but public private key is not allowed. I tried for Net::SSH::Perl etc but these are not built in perl distribution (active perl on windows or part of perl distribution of linux / solaris). Can we do it via IO::Socket::INET ? Thanks Regards, Amit Saxena Thanks Shawn for the reply. Actually my requirement, to be specific, is as follows. The script will be executed in periodic fashion from a *nix server and the script will initiate a ssh connection to itself using perl. This is to confirm that the ssh service is running and there is no issue in getting a new and authenticated ssh session when clients will connect to the server via ssh externally. Please suggest. Thanks Regards, Amit Saxena [Non-text portions of this message have been removed] [Non-text portions of this message have been removed] __._,_.___ Reply to senderj...@pepersack.net?subject=re%3a%20%5bpbml%5d%20re%3a%20monitoring%20ssh%20connectivity%20to%20a%20server%20using%20perl%20%21| Reply to groupperl-begin...@yahoogroups.com?subject=re%3a%20%5bpbml%5d%20re%3a%20monitoring%20ssh%20connectivity%20to%20a%20server%20using%20perl%20%21| Reply via web posthttp://groups.yahoo.com/group/perl-beginner/post;_ylc=X3oDMTJxdXFrZ3M2BF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBG1zZ0lkAzI3MDU5BHNlYwNmdHIEc2xrA3JwbHkEc3RpbWUDMTI5MDU0NDI0MA--?act=replymessageNum=27059| Start a New Topichttp://groups.yahoo.com/group/perl-beginner/post;_ylc=X3oDMTJlZXNka2FjBF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBHNlYwNmdHIEc2xrA250cGMEc3RpbWUDMTI5MDU0NDI0MA-- Messages in this topichttp://groups.yahoo.com/group/perl-beginner/message/27057;_ylc=X3oDMTM2amt1MmljBF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBG1zZ0lkAzI3MDU5BHNlYwNmdHIEc2xrA3Z0cGMEc3RpbWUDMTI5MDU0NDI0MAR0cGNJZAMyNzA1Nw--( 3) Recent Activity: - New Membershttp://groups.yahoo.com/group/perl-beginner/members;_ylc=X3oDMTJmbjFsMnFsBF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBHNlYwN2dGwEc2xrA3ZtYnJzBHN0aW1lAzEyOTA1NDQyNDA-?o=6 2 Visit Your Grouphttp://groups.yahoo.com/group/perl-beginner;_ylc=X3oDMTJlNW5yNHI4BF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBHNlYwN2dGwEc2xrA3ZnaHAEc3RpbWUDMTI5MDU0NDI0MA-- Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html [image: Yahoo! Groups]http://groups.yahoo.com/;_ylc=X3oDMTJkNnE2NTBwBF9TAzk3MzU5NzE0BGdycElkAzEyMjM4NTcEZ3Jwc3BJZAMxNzA1MDA2OTUxBHNlYwNmdHIEc2xrA2dmcARzdGltZQMxMjkwNTQ0MjQw Switch to: Text-Onlyperl-beginner-traditio...@yahoogroups.com?subject=change+delivery+format:+Traditional, Daily Digestperl-beginner-dig...@yahoogroups.com?subject=email+delivery:+Digest• Unsubscribeperl-beginner-unsubscr...@yahoogroups.com?subject=unsubscribe• Terms of Use http://docs.yahoo.com/info/terms/ . __,_._,___ Hi Joe, I feel, I have to settle for this option in the end. However is there a way to NOT to use public-private key with ssh and have embedded password in the ssh command itself to have non interactive output ? Thanks Regards, Amit Saxena
How to copy and execute a file from source host to a remote windows system using perl ?
Hi all, Please let me know a way to copying from source host and executing a file on a remote windows system using perl when 1. When the password of administrator account on the remote host is known. 2. When the password of the domain administrator account, to which remote windows host is part of, is known. The source host can be considered either as *nix host or windows host. Thanks Regards, Amit Saxena
Re: [PBML] Help needed in recursion with objects in perl !
On Fri, Aug 6, 2010 at 8:09 PM, Randal L. Schwartz mer...@stonehenge.comwrote: Amit == Amit Saxena learn.tech...@gmail.com writes: Amit I am working on a tree implementation (with any number of parent Amit and child nodes) in perl. Every node is defined as a object of a Amit Node class which I have created as a .pm module. Unless this is for a student exercise, you probably just want to look at Graph in the CPAN. Lots and lots and lots of graph traversal things already worked out for you. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion Thanks Randal for the reply. The purpose of this activity is to model a hierarchical representation of dependent components, each of one will be represented as a service. I had a look at the Graph module ( http://search.cpan.org/~jhi/Graph-0.94/lib/Graph.pod) but I am not sure how it can be used to implement multiple parent and multiple child implementation of a tree. In other words, I would like to have similar methods which are available in the Tree implementations in CPAN. Please suggest. Thanks Regards, Amit Saxena
Help needed in recursion with objects in perl !
Hi all, I am working on a tree implementation (with any number of parent and child nodes) in perl. Every node is defined as a object of a Node class which I have created as a .pm module. I have defined a method getParentNodes which returns reference to an array having all the (immediate) parent nodes objects as shown below. my @immediate_parent_node_objects = $node1-getParentNodes (); my $i; foreach $i ( @{$node1-getParentNodes ()} ) { print Parent node for the child node . $node1-getNodeName() . is . $i-getNodeName() \n; } I want to define another method named getParentNodesRecurse which will return either all or upto a level of (ancestor) parent nodes objects instead of immediate parent node objects. I tried to implement something similar to what's shown below but I am unable to achieve it. sub getParentNodesRecurse { my ( $self, $level ) = @_; print \t x $level . node name = [ . $self-getNodeName() . ], level = [$level]\n; #print level = [$level]\n; if ( ! defined $self-getParentNodes() ) { print \t x $level . (No parent nodes for the node [ . $self-getNodeName() . ])\n; return; } my @concatenated_list_of_parent_nodes; my $l; foreach $l ( @{$self-getParentNodes()} ) { @concatenated_list_of_parent_nodes = ( @concatenated_list_of_parent_nodes, getParentNodesRecurse( $l, $level+1 ) ); } print \n; print Returning the concatenation of following two lists : \n; print . @{$self-getParentNodes()} . \n; print [ . @concatenated_list_of_parent_nodes . ]\n; print \n; return ( \( @{$self-getParentNodes()}, @concatenated_list_of_parent_nodes ) ); } Please help and also let me know in case there is a better way to implement. I can even rewrite my implementation using different design. I tried looking for modules on CPAN which supports tree implementation with multiple parents and child but couldn't find it. Note : For some reasons, I don't want to use implementation which requires $_. Thanks Regards, Amit Saxena
How to become a perl architect !
Hi all, I have around 6+ years of IT experience as a software development mailing in scripting technologies using perl. I want to become technical architect in perl. Please help me / suggest me / guide me on how should I start. Also please tell me any resources which could help me. On perl, I have mainly experience on text handling and processing. Thanks Regards, Amit Saxena
Re: How to become a perl architect !
On Fri, Jul 2, 2010 at 9:48 AM, Shlomi Fish shlo...@iglu.org.il wrote: On Friday 02 Jul 2010 12:34:05 Amit Saxena wrote: Hi all, I have around 6+ years of IT experience as a software development mailing in scripting technologies using perl. I want to become technical architect in perl. Please help me / suggest me / guide me on how should I start. Also please tell me any resources which could help me. On perl, I have mainly experience on text handling and processing. Well, assuming I know what you mean by Perl Architect: 1. Head over to http://perl-begin.org/ and go over all the pages seeing what you know and don't know. 2. Read the book Perl Best Practices : http://perl-begin.org/books/advanced/#pbp 3. Read the Moose introductory documentation: http://www.iinteractive.com/moose/about.html 4. Maybe read chromatic's Modern Perl book: http://www.modernperlbooks.com/mt/2010/06/modern-perl-the-book-the-draft.html 5. Contribute to CPAN modules and other Perl code. 6. Other recommended books: http://www.shlomifish.org/philosophy/books-recommends/ Hope it helps. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Parody on The Fountainhead - http://shlom.in/towtf God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . Hi Shlomi, I am already following two books in my regular perl development work. Those books are Programming Perl third edition and Perl Best Practices. I am not planning to stop working as a developer, however apart from my regular development work I also want to now start learning about Perl architect that is working for designing (and not coding) an implementation that's ultimately going to be implemented in Perl at least. I hope if there was some confusion earlier, I have resolved the same. Now as the understanding is clear, please suggest what all to read / refer etc apart from my regular Perl development work so that I can slowly start working for a Perl architect. I know it will take lots of time but at least it needs to be started at some time. Thanks Regards, Amit Saxena
Re: How to become a perl architect !
On Fri, Jul 2, 2010 at 11:26 AM, Chas. Owens chas.ow...@gmail.com wrote: On Fri, Jul 2, 2010 at 05:56, Amit Saxena learn.tech...@gmail.com wrote: snip On perl, I have mainly experience on text handling and processing. snip I am not planning to stop working as a developer, however apart from my regular development work I also want to now start learning about Perl architect that is working for designing (and not coding) an implementation that's ultimately going to be implemented in Perl at least. I hope if there was some confusion earlier, I have resolved the same. Now as the understanding is clear, please suggest what all to read / refer etc apart from my regular Perl development work so that I can slowly start working for a Perl architect. I know it will take lots of time but at least it needs to be started at some time. snip It is still not 100% clear what you are asking, but I will take a shot at restating your question. Tell us if this is not what you are asking: I have been a Perl programmer for 7 years and reached the point where just writing what other people have specified is no longer rewarding. I want to be the one who designs the systems that others (or myself) write. If that is in fact what you are asking, then you should get a CS degree if you don't have one or refresh your knowledge of algorithms and data structures if you do. The book [Mastering Algorithms with Perl][1] may be helpful in this regard. You should read books like [How to Design Programs][2], [Design Patterns][3], and [Antipatterns][4]. It is important to remember that design is largely language agnostic, so do not limit yourself to Perl resources. You should find other programs that are in the same class as the ones you want to design, and then study how they fit together. [1]: http://oreilly.com/catalog/9781565923980 [2]: http://www.htdp.org/ [3]: http://en.wikipedia.org/wiki/Design_Patterns [4]: http://en.wikipedia.org/wiki/Antipatterns -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. Hi, That's exactly what I want. Though I myself a CS graduate and post-graduate, I will still go through the book Mastering Algorithms with Perl. I will also go through the links you have posted. Thanks for the reply. Thanks Regards, Amit Saxena
Re: How to become a perl architect !
On Fri, Jul 2, 2010 at 9:41 PM, Peter Scott pe...@psdt.com wrote: On Fri, 02 Jul 2010 09:34:05 +, Amit Saxena wrote: I have around 6+ years of IT experience as a software development mailing in scripting technologies using perl. I want to become technical architect in perl. Please help me / suggest me / guide me on how should I start. Also please tell me any resources which could help me. I have been developing in Perl for 20 years and doing enterprise architecture for 10 years. But I have no idea what a Perl architect is. Please explain in more detail. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ http://www.informit.com/store/product.aspx?isbn=0137001274 http://www.oreillyschool.com/courses/perl1/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Hi Peter, Perl is my main skill and I wanted to learn how to design and develop enterprise applications in Perl. Development is OK but how to design is something I want to know. So far, I am only developing small application components in Perl but now I want to learn how to design the whole system and subsequently develop in Perl. I might have incorrectly stated the term Perl architect but I hope you now have got the idea of what I want to now learn. If yes, then please suggest. Thanks Regards, Amit Saxena
How to find the status, i.e. next run time and last run time, of a task which is run through windows task scheduler !
Hi all, I want to know how to find the status, i.e. next run time and last run time, of a task which is run through windows task scheduler. This is required so as to find out instances where a task gets hanged after run through windows task scheduler. Thanks Regards, Amit Saxena
Developing Complex Event Processing (CEP) applications in perl
Hello all, Please let me know if anybody has any idea on the development of Complex Event Processing (CEP) applications in perl. I have been assigned a task for development of a complex event processing (CEP) application and I would like to do the same in perl that is my favorite language. Thanks Regards, Amit Saxena
Re: Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?
On Fri, Apr 30, 2010 at 10:40 PM, C.DeRykus dery...@gmail.com wrote: On Apr 30, 3:55 am, learn.tech...@gmail.com (Amit Saxena) wrote: Hello everybody, Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ? As a reference, in the following code below, I want to perform the substitution of ~ character with _ character to the value of \3 inside a regular expression so that $3 ultimately becomes are___you___fine? instead of are~~~you~~~fine?. I tried checking with the perl docs but of no help. The only hope is using (?{}) which not only is experimental but also doesn't allow me to modify the value of \3 inside a regular expression. Note : The reason why I want a solution entirely based on regular expression because this regular expression will be used in a tool which supports usage of perl regular expression inside its configuration file. The source code as well as the output is mentioned below. Please suggest. == [r...@host1 ~]# [r...@host1 ~]# cat check.pl #!/usr/bin/perl use strict; use warnings; my $text1 = q/hello~~~how~~~are~~~you~~~fine?~~~OK/; my $regex1 = qr/^([^\~]+)\~\~\~([^\~]+)(?:\~\~\~){0,1}(.*)\~\~\~([^\~]+)$/; print \n; print text1 is [$text1]\n\n; print regex1 is [$regex1]\n\n; if ( $text1 =~ /$regex1/ ) { print Regular expression matched\n\n; print Field 1 : [$1]\n; print Field 2 : [$2]\n; print Field 3 : [$3]\n; print Field 4 : [$4]\n; print \n;} else { print Regular expressing didn't matched\n\n;} [r...@host1 ~]# [r...@host1 ~]# perl check.pl text1 is [hello~~~how~~~are~~~you~~~fine?~~~OK] regex1 is [(?-xism:^([^~]+)~~~([^~]+)(?:~~~){0,1}(.*)~~~([^~]+)$)] Regular expression matched Field 1 : [hello] Field 2 : [how] Field 3 : [are~~~you~~~fine?] Field 4 : [OK] Not exclusively a regex but here's an option: my $regex1 = qr/^( # field 1 - new capture ([^~]+) # field 2 ~~~ ([^~]+) # field 3 (?:~~~){0,1} )# end field 1 (needed for length) (.*) # target field 4 ~~~ ([^~]+)$ # final field5 /x; if ( $text1 =~ /$regex1/ ) { ( my $target = $4 ) =~ tr/~/_/; substr( $text1, length($1), length($4), $target ); # extra substr arg } orig: [hello~~~how~~~are~~~you~~~fine?~~~OK] change: [hello~~~how~~~are___you___fine?~~~OK] Perl 5.10 has named captures which'd make this more readable. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Thanks Charles but this will not work as the tool only accepts perl regular expressions but not any perl code statements etc. Thanks anyway. Regards, Amit Saxena
Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ?
Hello everybody, Can we perform substitution to the matched pattern inside a regular expression so that the modified pattern gets returned instead of earlier matched one ? As a reference, in the following code below, I want to perform the substitution of ~ character with _ character to the value of \3 inside a regular expression so that $3 ultimately becomes are___you___fine? instead of are~~~you~~~fine?. I tried checking with the perl docs but of no help. The only hope is using (?{}) which not only is experimental but also doesn't allow me to modify the value of \3 inside a regular expression. Note : The reason why I want a solution entirely based on regular expression because this regular expression will be used in a tool which supports usage of perl regular expression inside its configuration file. The source code as well as the output is mentioned below. Please suggest. == [r...@host1 ~]# [r...@host1 ~]# cat check.pl #!/usr/bin/perl use strict; use warnings; my $text1 = q/hello~~~how~~~are~~~you~~~fine?~~~OK/; my $regex1 = qr/^([^\~]+)\~\~\~([^\~]+)(?:\~\~\~){0,1}(.*)\~\~\~([^\~]+)$/; print \n; print text1 is [$text1]\n\n; print regex1 is [$regex1]\n\n; if ( $text1 =~ /$regex1/ ) { print Regular expression matched\n\n; print Field 1 : [$1]\n; print Field 2 : [$2]\n; print Field 3 : [$3]\n; print Field 4 : [$4]\n; print \n; } else { print Regular expressing didn't matched\n\n; } [r...@host1 ~]# [r...@host1 ~]# perl check.pl text1 is [hello~~~how~~~are~~~you~~~fine?~~~OK] regex1 is [(?-xism:^([^~]+)~~~([^~]+)(?:~~~){0,1}(.*)~~~([^~]+)$)] Regular expression matched Field 1 : [hello] Field 2 : [how] Field 3 : [are~~~you~~~fine?] Field 4 : [OK] [r...@host1 ~]# == Thanks Regards, Amit Saxena
How to implement ping script to monitor server up/down state in perl ?
Hi all, I want a perl ping script (console based) to monitor server up/down state. So far I have tried two different approaches, though none of them were successful. *First Approach* Call the operating system ping command from the Perl program and get the server up/down state. Call this program every few minutes using operating system specific scheduler. *Second Approach* Instead of operating system ping, use Net::Ping module from CPAN. The program with both the approaches are that they are reactive in nature rather than proactive. If the server goes down and goes up again between two consecutive instances of perl program execution, the perl program will never get to know about the same. Lowering the interval might help here but instead increases the workload on the server (probably). Having said all that, I have following doubts. 1. Is there a way to implement a daemon sort of a thing in Perl which will continuously listen at one port and proactively monitor the ping state of the server ? 2. I have heard about SNMP and also know about perl Net::SNMP and SNMP modules. Will they be of any help here ? Thanks Regards, Amit Saxena
Re: How to implement ping script to monitor server up/down state in perl ?
Hi Thomas, Thanks for the response. The client for which I am working will not allow any external utility / modules to be installed on their development / production environments. Moreover they want the solution implemented using Perl only. Thanks Regards, Amit Saxena On Tue, Jul 21, 2009 at 4:43 AM, Thomas Bätzler t.baetz...@bringe.comwrote: Amit Saxena learn.tech...@gmail.com asked: I want a perl ping script (console based) to monitor server up/down state. Why re-invent the wheel when there's already stuff like mon ( http://mon.wiki.kernel.org/index.php/Main_Page) or nagios ( http://www.nagios.org/)? HTH, Thomas
Re: How to implement ping script to monitor server up/down state in perl ?
Thanks Thomas, I will surely look at mon to know about how to write monitoring code in Perl. Thanks Regards, Amit Saxena On Tue, Jul 21, 2009 at 5:25 AM, Thomas Bätzler t.baetz...@bringe.comwrote: Amit Saxena learn.tech...@gmail.com wrote: Hi Thomas, Thanks for the response. The client for which I am working will not allow any external utility / modules to be installed on their development / production environments. Moreover they want the solution implemented using Perl only. Actually, mon ist pure Perl, so it should fit the bill on that count. Depending on the OS/distro your customer is using, they might even be able to install a mon package from one of their trusted sources. Even if you're not going to use mon, it should provide you with a wealth of ideas on how to write monitoring code in Perl. HTH, Thomas
Re: How to implement ping script to monitor server up/down state in perl ?
Hi Bob, It seems there is some confusion. I just want to monitor remote server connectivity (either through ping or something else) but I don't want to call my programs every few intervals etc. What I want is a daemon sort of a thing in Perl running either on the source system (preferably) or on the destination system which will automatically send some alert etc (which my Perl recognizes) in case of network disconnection etc. Your suggestion to open a connection at particular port etc sounds good but the only issue I will have is to open that connection again when the network is up. Thanks Regards, Amit Saxena On Tue, Jul 21, 2009 at 5:24 AM, Bob McConnell r...@cbord.com wrote: From: Amit Saxena The client for which I am working will not allow any external utility / modules to be installed on their development / production environments. Moreover they want the solution implemented using Perl only. If they won't allow any utilities, how will you install this one? They have to learn how be reasonable before you will be able to do much for them. Ping will only tell you that the target computer is up, still connected to the network and reachable from your workstation. It won't tell you if the particular service[*] you want to monitor is still alive. For that you need to create a thread that actively monitors that service. It has to open a connection to the service and keep it open. Then either send an empty message periodically over that connection or set the keep-alive interval to some reasonable period and enable them. How you determine that period depends on how quickly you need to know the server is down. No, the two hour default is not reasonable. For POS systems that need real-time responses we set a sixty second interval. That way we know about network, server or workstation outages within two minutes. Bob McConnell [*] See /etc/services for service to port map. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Finding out matching and not matching entries between two files !
Hi all, I need help regarding the approach to find out matched and unmatched entries between two files using perl. As the number of lines in the files would be around 10k-50k, I don't want to load entire file contents into memory. The first file (file1 also known as superset file) contains all the data in 4 columns in a format like country, state, city and id. The second file (file2 also known as subset file) contains some of the data from superset file with additional condition that it does not contains all 4 columns. Instead it contains 3 columns only. The following information is needed from these input files 1. Matched file . which lists the contents of the superset file which matches the contents of subset file. 2. Unmatched file .given all the ids for the country - state pair from the subset file, list down all the rows from the superset file which contains the same country - state pair but none of those ids. The sample files are shown below. File 1 (Superset) Country1,State1,City111,id1 Country1,State1,City112,id2 Country1,State1,City113,id3 Country1,State1,City114,id4 Country1,State1,City115,id5 Country1,State2,City121,id6 Country1,State2,City122,id7 Country1,State2,City123,id8 Country1,State3,City131,id9 Country1,State3,City132,id10 File 2 (subset) Country1,State1,City111 Country1,State1,City112 Country1,State2,City121 Country1,State3,City131 Matched file Country1,State1,City111,id1 Country1,State1,City112,id2 Country1,State2,City121,id6 Country1,State3,City131,id9 Unmatched file -- Country1,State1,City113,id3 Country1,State1,City114,id4 Country1,State1,City115,id5 Country1,State2,City122,id7 Country1,State2,City123,id8 Country1,State3,City132,id10 As of now, I am reading the subset file line by line and then once there is a difference in country and state pair, I find out all records in superset file which satisfies matching and unmatching condition. Please suggest a better approach for the same. Thanks Regards, Amit Saxena
Re: Finding out matching and not matching entries between two files !
Hi Jim, Thanks for the response. I was doing the approach which you have mentioned as the fastest one. I was using nested data structures for the same. The only problem with that approach which I faced are :- 1. The code was getting too much complex due to use of too many references to implement nested data structure. 2. Finding out the matched line was not much of an issue, however I wanted to find out the unmatched records and that's where i had to scan the files more than twice. Perhaps my algorithm was not efficient but as performance is not the criteria for my script, I can afford the same. Is there any CPAN module (preferably built-in) which takes a CSV or character delimited file as an input and generate a nested data structure containing entire file contents automatically. Also is there any module for file comparison of two similar format files. Thanks Regards, Amit Saxena On Thu, Jul 16, 2009 at 7:18 AM, Jim Gibson jimsgib...@gmail.com wrote: At 2:12 AM -0700 7/16/09, Amit Saxena wrote: Hi all, I need help regarding the approach to find out matched and unmatched entries between two files using perl. As the number of lines in the files would be around 10k-50k, I don't want to load entire file contents into memory. The fastest approach is usually to load the shorter of the two files into memory, then read the longer of the two files and process each line, recording whether the line matches any record in the shorter file. A hash is best for this method. 50k files should be no problem. If you really don't or can't read one of the files into memory, then a method that still requires only one pass over each of the two files is to sort the files and save the sorted copies. Then, read one line from each file and compare. If they are equal, record this fact and read two more lines. If they do not match, record the fact and read a line from the file with the lessor of the two line, alphabetically speaking, then compare again. -- Jim Gibson j...@gibson.org
Re: How to login from one system (A) into remote system (B) and do a ping to the third system (C) with Perl and CGI !
On Fri, Apr 10, 2009 at 11:48 AM, Zhao, Bingfeng bingfeng.z...@ca.comwrote: With windows platform, there is also a similar way, you can use psexec utility from sysinternals, now acquired by Microsoft - http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx I had done a lot remote management with it and, of course, perl:) -Original Message- From: kevin liu [mailto:lwtben...@gmail.com] Sent: Friday, April 10, 2009 10:13 To: Amit Saxena Cc: Perl Beginners Subject: Re: How to login from one system (A) into remote system (B) and do a ping to the third system (C) with Perl and CGI ! I think this depends on what kind of OS you are using. If you are working between Unix like operating system, you could directly use ssh, even remsh to log on to another system. On Thu, Apr 2, 2009 at 1:04 AM, Amit Saxena learn.tech...@gmail.com wrote: Hello everybody, I need to write a Perl CGI script to login from one system (A) into remote system (B) and do a ping to the third system (C). As of now, I have successfully written the code in Perl CGI to Ping any host / IP using built it Perl Net::Ping module. However I am not sure how to login (preferably using ssh) into a remote system using Perl and execute our ping script over there. I searched on CPAN and found one module Net::SSH::Perl http://search.cpan.org/~turnstep/Net-SSH-Perl-1.34/lib/Net/SSH/Perl.pmh ttp://search.cpan.org/%7Eturnstep/Net-SSH-Perl-1.34/lib/Net/SSH/Perl.pm which seems to allow login into remote system and execute commands over there. However I am looking for any built-in module for the same as the administrators will not allow external modules to be installed in production environment. Thanks Regards, Amit Saxena Hello all, Thanks for the replies and the help. Since last few weeks, I am also trying for a solution to the same. So far, what I am trying and did is to use the module Net::SSH in Perl on rhel 5. Net::SSH allows me to connect to a remote system using a username and host only with already setup ssh public/private keys (rsa keys without a passphrase). The program is working fine in the console mode but I am unable to connect in the Perl CGI. The program is copied below . The program though prints the message Connected to server [] using the user [] and executing the command [uname -a] in the output web page but it does not goes inside the while (READER) loop. In the console output, the same program works fine ! Note :- 1. None of the other modules which I have seen on CPAN allows me to connect to remote system, execute commands and get the output without putting hardcoded (and clear text) password in the code (which is preferred approach). Unless there is no other solution and this solution does not works, I will lookout finally for solution with the password in the code. 2. The Perl CGI program is launched through a right-click menu from the output rows in IBM netcool output. IBM Netcool allows a CGI to be launched from the output interface. 3. I also tried executing remote commands using ssh through system / backticks but it does not seems to be working. Please suggest. Code : #! /usr/bin/perl -w use strict; use warnings; use Net::Ping; use Time::HiRes; use Net::SSH qw(sshopen2); use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); $| = 1; $ENV{PATH} = /usr/local/bin:/usr/bin:/bin; $ENV{HOME} = ( getpwuid $ )[ -2 ]; $ENV{SSH_ASKPASS} = /usr/libexec/openssh/gnome-ssh-askpass; my $cgi_object = new CGI; print $cgi_object-header; print $cgi_object-start_html ( -title = 'IBM Tivoli Netcool/Webtop', -onLoad = window.moveTo(0,0); window.resizeTo(screen.availWidth, screen.availHeight) ); my $host_ip_name1; my $number_of_ping_requests1; my $timeout1; my $Submit_Data; my $display_results = 1; if ( ( ! defined $cgi_object-param('Submit_Data') ) ( defined $cgi_object-param(\$selected_rows.Node) ) ) { $host_ip_name1 = $cgi_object-param(\$selected_rows.Node); if ( ( $host_ip_name1 =~ /^ *$/ ) or ( ! defined $host_ip_name1 ) ) { $display_results = 0; } else { $display_results = 1; } } elsif ( ( ! defined $cgi_object-param('Submit_Data') ) ( ! defined $cgi_object-param(\$selected_rows.Node) ) ) { $display_results = 0; } elsif ( defined $cgi_object-param('Submit_Data') ) { $display_results = 1; $Submit_Data = $cgi_object-param('Submit_Data'); $host_ip_name1 = $cgi_object-param('host_ip_name'); $number_of_ping_requests1 = $cgi_object-param('number_of_ping_requests'); $timeout1 = $cgi_object-param('timeout'); } $host_ip_name1 = if ! defined $host_ip_name1; $number_of_ping_requests1 = 4 if ! defined $number_of_ping_requests1; $timeout1 = 2 if ! defined $timeout1; print __STYLE__; STYLE type=text/css h1.headerTool { font-size: 30pt; font-style: italic; font-weight: bold; letter-spacing: -4px; } .headerReg, .headerTM { font-size: 12pt; vertical-align: super; } .headerWebtop { font
How to login from one system (A) into remote system (B) and do a ping to the third system (C) with Perl and CGI !
Hello everybody, I need to write a Perl CGI script to login from one system (A) into remote system (B) and do a ping to the third system (C). As of now, I have successfully written the code in Perl CGI to Ping any host / IP using built it Perl Net::Ping module. However I am not sure how to login (preferably using ssh) into a remote system using Perl and execute our ping script over there. I searched on CPAN and found one module Net::SSH::Perlhttp://search.cpan.org/~turnstep/Net-SSH-Perl-1.34/lib/Net/SSH/Perl.pmwhich seems to allow login into remote system and execute commands over there. However I am looking for any built-in module for the same as the administrators will not allow external modules to be installed in production environment. Thanks Regards, Amit Saxena
How to implement tail -f using perl in both windows and linux !
Is it possible to implement this without using any external modules from CPAN ? Thanks Regards, Amit Saxena
Re: Recursive regular expression not working !
On Wed, Dec 24, 2008 at 7:11 PM, Mr. Shawn H. Corey shawnhco...@magma.cawrote: On Wed, 2008-12-24 at 11:40 +0530, Amit Saxena wrote: Hi all, I am trying to use recursive regular expression in Perl. I am using an example from http://www.perl.com/pub/a/2003/06/06/regexps.html. Whenever I try to execute the program, it hangs and I have to do a CNTRL-C to break it. Please let me know where I am wrong. *# cat t_r.pl* #! /usr/bin/perl use warnings; use strict; my $paren = qr/ \( [^)]+ \) /x; Some (parenthesized) text =~ /($paren)/; print $1; # parenthesized $paren = qr/ \( ( [^()]+ # Not parens | (??{ $paren }) # Another balanced group (not interpolated yet) )+? \) /x; print \n; Some (parenthesised and (gratuitously) sub-parenthesised text =~ /($paren)/; print $1; # parenthesized print \n; *# perl t_r.pl* (parenthesized) Control-Break *# perl -v* This is perl, v5.8.5 built for i386-linux-thread-multi Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.com/, the Perl Home Page. *#* I don't think you're doing anything wrong. I think the guy who wrote the web page didn't test his regex with a string with unbalanced parenthesis. Try: Some (parenthesised and (gratuitously) sub-parenthesised) text =~ /($paren)/; You cannot parse unbound-nested contexts with regular expressions. You need a finite-state automation (FSA) with a push-down stack. -- Just my 0.0002 million dollars worth, Shawn Believe in the Gods but row away from the rocks. -- ancient Hindu proverb Thanks for the response Shawn. However when I try to execute it even with the proper text, I get the different output than anticipated. *# cat t_r.pl* #! /usr/bin/perl use warnings; use strict; my $paren = qr/ \( [^)]+ \) /x; Some (parenthesized) text =~ /($paren)/; print $1; # parenthesized $paren = qr/ \( ( [^()]+ # Not parens | (??{ $paren }) # Another balanced group (not interpolated yet) )+? \) /x; print \n; Some (parenthesised and (gratuitously) sub-parenthesised text) =~ /($paren)/; print $1\n; print $2\n; print \n; *# perl t_r.pl* (parenthesized) (parenthesised and (gratuitously) sub-parenthesised text) sub-parenthesised text *#* I was expecting $2 to be gratuitously instead of sub-parenthesized text. Please let me know whether there is some difference in my understanding here. Regards, Amit Saxena
Recursive regular expression not working !
Hi all, I am trying to use recursive regular expression in Perl. I am using an example from http://www.perl.com/pub/a/2003/06/06/regexps.html. Whenever I try to execute the program, it hangs and I have to do a CNTRL-C to break it. Please let me know where I am wrong. *# cat t_r.pl* #! /usr/bin/perl use warnings; use strict; my $paren = qr/ \( [^)]+ \) /x; Some (parenthesized) text =~ /($paren)/; print $1; # parenthesized $paren = qr/ \( ( [^()]+ # Not parens | (??{ $paren }) # Another balanced group (not interpolated yet) )+? \) /x; print \n; Some (parenthesised and (gratuitously) sub-parenthesised text =~ /($paren)/; print $1; # parenthesized print \n; *# perl t_r.pl* (parenthesized) Control-Break *# perl -v* This is perl, v5.8.5 built for i386-linux-thread-multi Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.com/, the Perl Home Page. *#*
Ways to get a mapping of values versus keys in a hash where there is one-to-one mapping between the keys and the values !
Hi all, I recently had one requirement where I needed to get the key in a hash on the basis of supplied value. There is one additional information that there is one to one mapping between the keys and the values. I was able to do that by defining a extra array and hash variables as shown in the program below but I feel this approach will not work for all scenarios like :- 1. When the value of a particular key is undef in the original hash. 2. When there are nested data structures. I have pasted the program as well as the output over here. *Prompt#* *cat test_hash_reverse.pl* #! /usr/bin/perl use strict; use warnings; my %h1 = ( N = North, E = East, W = West, S = South, C = Central ); print The Hash h1 is printed below :-\n; foreach my $var1 (keys %h1) { print \t[$var1] = [$h1{$var1}]\n; } my @arr1 = %h1; print The Array arr1 as initialized from the Hash h1 is printed below :-\n; print @arr1\n; my @arr2 = reverse (@arr1); print The Array arr2 as initialized from the reverse of the Array arr1 is printed below :-\n; print @arr2\n; my %h2 = @arr2; print The Hash h2 as initialized from the Array arr2 is printed below :-\n; foreach my $var2 (keys %h2) { print \t[$var2] = [$h2{$var2}]\n; } *Prompt #* *perl test_hash_reverse.pl* The Hash h1 is printed below :- [S] = [South] [W] = [West] [C] = [Central] [N] = [North] [E] = [East] The Array arr1 as initialized from the Hash h1 is printed below :- S South W West C Central N North E East The Array arr2 as initialized from the reverse of the Array arr1 is printed below :- East E North N Central C West W South S The Hash h2 as initialized from the Array arr2 is printed below :- [West] = [W] [Central] = [C] [South] = [S] [North] = [N] [East] = [E] *Prompt #* Thanks Regards, Amit Saxena
Re: Ways to get a mapping of values versus keys in a hash where there is one-to-one mapping between the keys and the values !
On Tue, Nov 25, 2008 at 10:59 PM, Rob Dixon [EMAIL PROTECTED] wrote: Amit Saxena wrote: Hi all, I recently had one requirement where I needed to get the key in a hash on the basis of supplied value. There is one additional information that there is one to one mapping between the keys and the values. I was able to do that by defining a extra array and hash variables as shown in the program below but I feel this approach will not work for all scenarios like :- 1. When the value of a particular key is undef in the original hash. 2. When there are nested data structures. I have pasted the program as well as the output over here. *Prompt#* *cat test_hash_reverse.pl* #! /usr/bin/perl use strict; use warnings; my %h1 = ( N = North, E = East, W = West, S = South, C = Central ); print The Hash h1 is printed below :-\n; foreach my $var1 (keys %h1) { print \t[$var1] = [$h1{$var1}]\n; } my @arr1 = %h1; print The Array arr1 as initialized from the Hash h1 is printed below :-\n; print @arr1\n; my @arr2 = reverse (@arr1); print The Array arr2 as initialized from the reverse of the Array arr1 is printed below :-\n; print @arr2\n; my %h2 = @arr2; print The Hash h2 as initialized from the Array arr2 is printed below :-\n; foreach my $var2 (keys %h2) { print \t[$var2] = [$h2{$var2}]\n; } *Prompt #* *perl test_hash_reverse.pl* The Hash h1 is printed below :- [S] = [South] [W] = [West] [C] = [Central] [N] = [North] [E] = [East] The Array arr1 as initialized from the Hash h1 is printed below :- S South W West C Central N North E East The Array arr2 as initialized from the reverse of the Array arr1 is printed below :- East E North N Central C West W South S The Hash h2 as initialized from the Array arr2 is printed below :- [West] = [W] [Central] = [C] [South] = [S] [North] = [N] [East] = [E] Hi Rob, My question is that is there any scenario where my solution fails ? Thanks Regards, Amit Saxena *Prompt #* You may as well just say my %h2 = reverse %h1; but what is your question? Rob
How to determine the file type of a file passed as an input to the perl program ?
Hi all, How to determine the file type of a file passed as an input to the perl program ? I want to have the same output as it's shown by file command in UNIX. Thanks Regards, Amit Saxena
Re: How to determine the file type of a file passed as an input to the perl program ?
On Thu, Nov 20, 2008 at 4:59 PM, Raymond Wan [EMAIL PROTECTED]wrote: Hi Amit, Amit Saxena wrote: Hi all, How to determine the file type of a file passed as an input to the perl program ? I want to have the same output as it's shown by file command in UNIX. Try going to CPAN and searching for it. For example, http://search.cpan.org/search?query=file+typemode=all Several options come up. See which one seems easiest to use... Ray Hi Ray, Before posting this query here, I indeed did a sample search on CPAN. However I want to have a solution using Perl inbuilt module instead of some external module as the system I am working on does not allows perl external modules to be installed. If you have use such modules, please suggest the one which is inbuilt in Perl and best for this scenario ? Thanks Regards, Amit Saxena
Re: How to determine the file type of a file passed as an input to the perl program ?
On Thu, Nov 20, 2008 at 5:50 PM, Raymond Wan [EMAIL PROTECTED]wrote: Hi Amit, Amit Saxena wrote: On Thu, Nov 20, 2008 at 4:59 PM, Raymond Wan [EMAIL PROTECTED] wrote: Hi Amit, Amit Saxena wrote: Hi all, How to determine the file type of a file passed as an input to the perl program ? I want to have the same output as it's shown by file command in UNIX. Try going to CPAN and searching for it. For example, http://search.cpan.org/search?query=file+typemode=all Several options come up. See which one seems easiest to use.. Hi Ray, Before posting this query here, I indeed did a sample search on CPAN. However I want to have a solution using Perl inbuilt module instead of some external module as the system I am working on does not allows perl external modules to be installed. If you have use such modules, please suggest the one which is inbuilt in Perl and best for this scenario ? Oh! Then you should be more specific and mention that you searched CPAN already. In-built? You mean that it is part of the Perl language? I'm not sure if there is one; perhaps someone else can help you -- but if there was one, then people would not have developed external ones and put them on CPAN. At least, that's what I would expect... If you are in a shared environment, perhaps you should look into installing external Perl modules in your local home directory instead? Is that disallowed as well? Ray Hi Ray, Using external modules in the home directory is not disallowed, in fact I keep using few CPAN modules from my home directory like PerlTidy etc. However the reason for which I want to use an inbuilt module because I need not ask sysadmin people to download and install an external module just for my requirement. I tried even looking for UNIX utility stat (it even has a Perl API) but it's not giving me what I want. If I don't get any module like this, I will be forced to use system (file) which I don't want to use. Thanks Regards, Amit Saxena
Re: How to determine the file type of a file passed as an input to the perl program ?
On Thu, Nov 20, 2008 at 6:20 PM, Raymond Wan [EMAIL PROTECTED]wrote: Hi Amit, Amit Saxena wrote: Using external modules in the home directory is not disallowed, in fact I keep using few CPAN modules from my home directory like PerlTidy etc. However the reason for which I want to use an inbuilt module because I need not ask sysadmin people to download and install an external module just for my requirement. I'm sorry, but I don't understand what you mean here... You DO have modules in your home directory, but you don't want to ask the sysadmins to download them for you? How did you get those modules in your home directory, then? By installing them in your home directory, I also mean that *you* download them yourself. At first, I thought the sysadmins are preventing you from installing for strange reasons (disk quota, etc.). So, in the absence of someone giving you an answer to your other question, you might want to look into how to do an install in your home directory. Check this out: http://servers.digitaldaze.com/extensions/perl/modules.html http://theoryx5.uwinnipeg.ca/CPAN/perl/lib/CPAN.html On the first page, scroll down to the bottom to where it talks about CPAN.pm. If that doesn't work, then download the source and compile as the top of the first link says. Of course...this is only if no one else can help you with your original question; I've certainly installed modules in my home directory without ever bothering the system administrator at all. And yes, using them should be faster than doing system (file)... Ray Hi Ray, There seems to be some confusion here, let me resolve it. I have already installed some Perl modules in my home directory using the procedure which is same as what's mentioned in those links as well. However I use these modules just to explore a new functionality or to test whether there is any new module which can serve better than the existing one. Excluding the user's home directories, any changes to the UNIX system for databases, application languages, system settings are carefully monitored and any request for the same goes through a channel where the requester needs to convince a team about why we need changes in the development environment. That's why I was exploring if there is already some built-in module, I can use and explore that. Thanks Regards, Amit Saxena
Re: How to determine the file type of a file passed as an input to the perl program ?
On Thu, Nov 20, 2008 at 6:59 PM, Raymond Wan [EMAIL PROTECTED]wrote: Hi Amit, Amit Saxena wrote: On Thu, Nov 20, 2008 at 6:20 PM, Raymond Wan [EMAIL PROTECTED] wrote: Hi Amit, Amit Saxena wrote: Using external modules in the home directory is not disallowed, in fact I keep using few CPAN modules from my home directory like PerlTidy etc. However the reason for which I want to use an inbuilt module because I need not ask sysadmin people to download and install an external module just for my requirement. I'm sorry, but I don't understand what you mean here... You DO have modules in your home directory, but you don't want to ask the sysadmins to download them for you? How did you get those modules in your home directory, then? By installing them in your home directory, I also mean that *you* download them yourself. At first, I thought the sysadmins are preventing you from installing for strange reasons (disk quota, etc.). So, in the absence of someone giving you an answer to your other question, you might want to look into how to do an install in your home directory. Check this out: http://servers.digitaldaze.com/extensions/perl/modules.html http://theoryx5.uwinnipeg.ca/CPAN/perl/lib/CPAN.html On the first page, scroll down to the bottom to where it talks about CPAN.pm. If that doesn't work, then download the source and compile as the top of the first link says. Of course...this is only if no one else can help you with your original question; I've certainly installed modules in my home directory without ever bothering the system administrator at all. And yes, using them should be faster than doing system (file)... Ray Hi Ray, There seems to be some confusion here, let me resolve it. I have already installed some Perl modules in my home directory using the procedure which is same as what's mentioned in those links as well. However I use these modules just to explore a new functionality or to test whether there is any new module which can serve better than the existing one. Excluding the user's home directories, any changes to the UNIX system for databases, application languages, system settings are carefully monitored and any request for the same goes through a channel where the requester needs to convince a team about why we need changes in the development environment. That's why I was exploring if there is already some built-in module, I can use and explore that. Sorry, but you haven't cleared things up any better for me. :-) Maybe you can try one more time with me... If you use the procedures listed in those links, you will be able to: a) install Perl modules in your home directory, b) allow you to explore new functionality and to test which option is best, c) remove or update them as you choose, and c) NOT make any changes to the Unix system because only *you* can use them and you are not modifying any of the system's settings by installing a Perl module I get this feeling that you think that installing a module is making a change to the system that would upset a system administrator. You really aren't (well, assuming you are on a Unix system). The changes you are making are really within your home directory -- that is all (and permissions will disallow you from making changes outside the home directory, even if you tried). Don't get me wrong...if you told me that you wanted a built-in module because you just want to and it is none of my business, then I'll stop. :-) But it sounds to me that you think installing a module locally [in your home directory] will have any change on the system *outside* of your home directory...it won't. The only reason why I would think a sysadmin would discourage it is if 200 students (say) installed the same module, then 200 times the diskspace would be used...multiply this by the number of modules the class needs; for this reason, I can see why a sysadmin would discourage even a local installation... Ray Hi Ray, What you have interpreted is not at all correct. I am fully aware that installing a module in my UNIX account home directory will not have any affect on the overall system and the changes will be applicable with in my account only. What I meant was that I always prefer to look for built-in module instead of external module from CPAN. Generally the process goes like this :- 1. I download and install modules on CPAN so as to avail a feature which is not available in the standard Perl distribution. 2. Once satisfied with the module, I raise a request to the system administrators to install that module in Perl standard location so that other developer's like me can use that by accessing it from the standard Perl library location and they don't need to install it in their respective home directories. 3. In continuation with the earlier point, generally it's tough to convince the team which decides on which all system level
Difference between passing ? versus :1, :2, :3 etc in prepare in Perl DBI !
Hi What's the difference between passing ? versus :1, :2, :3 etc in prepare in Perl DBI ? For example, what's the difference between following two scenarios :- *Scenario 1* $sth = $dbh-prepare(insert into tablename values (:1, :2, :3)); $sth-execute($var1,$var2,$var3); *Scenario 2* $sth = $dbh-prepare(insert into tablename values (?, ?, ?)); $sth-execute($var1,$var2,$var3); Thanks Regards, Amit Saxena
Re: Difference between passing ? versus :1, :2, :3 etc in prepare in Perl DBI !
On Mon, Nov 3, 2008 at 11:43 AM, Chas. Owens [EMAIL PROTECTED] wrote: On Mon, Nov 3, 2008 at 00:58, Amit Saxena [EMAIL PROTECTED] wrote: Hi What's the difference between passing ? versus :1, :2, :3 etc in prepare in Perl DBI ? For example, what's the difference between following two scenarios :- *Scenario 1* $sth = $dbh-prepare(insert into tablename values (:1, :2, :3)); $sth-execute($var1,$var2,$var3); *Scenario 2* $sth = $dbh-prepare(insert into tablename values (?, ?, ?)); $sth-execute($var1,$var2,$var3); Thanks Regards, Amit Saxena from http://search.cpan.org/~timb/DBI-1.607/DBI.pm#Placeholders_and_Bind_Valueshttp://search.cpan.org/%7Etimb/DBI-1.607/DBI.pm#Placeholders_and_Bind_Values Some drivers also allow placeholders like :name and :N (e.g., :1, :2, and so on) in addition to ?, but their use is not portable. If the :N form of placeholder is supported by the driver you're using, then you should be able to use either bind_param or execute to bind values. Check your driver documentation. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. Thanks for the help. I am not clear with both of them. Regards, Amit Saxena
Issue with references and array slice with one member !
Hello all, Recently I faced one scenario with references and array slice in perl. I used following program to retrieve the rows from a table in Oracle using Perl DBI. As shown in the program, I did following steps to retrieve the rows :- - used fetchall_arrayref to get the array reference to the complete table - dereferenced the reference fetchall_arrayref and iterate one by one over each row $row in a foreach loop - further deferenced $row to get the columns one by one Now here is the problem, I used ${$row}[0], ${$row}[1] etc one by one to get all the columns for a particular code. On one of the production code which I am working, they have used @{$row}[0] , @{$row}[0] instead of earlier. The results for both of them were same. When I did a through debugging on this, I found that @{$row}[0] or @{$row}[1] etc is taken as array slice by perl with only one member so it returns the value of the column in scalar and not in list context. With ${$row}[0] or ${$row}[1] etc, the column value is returned in scaler context. I want to know whether it's appropriate to use @{$row}[0] , @{$row}[1] instead of ${$row}[0], ${$row}[1] though both of them gives same result ? # cat o1.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # Example PERL DBI/DBD Oracle Example on Oracle 10g use strict; use warnings; use DBI; my $dbname = *; ## DB Name from tnsnames.ora my $user = *; my $passwd = *; Connect to the database and return a database handle my $dbh = DBI-connect(dbi:Oracle:${dbname}, $user, $passwd); if($dbh){ print(Connected as user $user\n); } else { print(Failed to connect!\n); exit; } Prepare and Execute a SQL Statement Handle my $sth = $dbh-prepare(SELECT owner,table_name,num_rows FROM all_tables); # my $sth = $dbh-prepare(SELECT * FROM all_tables); $sth-execute(); my $allTablesRow = $sth-fetchall_arrayref(); foreach my $row (@{$allTablesRow}) { if (defined ${$row}[0]) { print ${$row}[0]; } else { print NULL; } if (defined ${$row}[1]) { print ${$row}[1]; } else { print NULL; } if (defined ${$row}[2]) { print ${$row}[2]; } else { print NULL; } print \n; } Disconnect #$dbh-disconnect; You have mail in /var/spool/mail/root # Thanks Regards, Amit Saxena
Re: any errors in this perl module?
On Fri, Sep 26, 2008 at 2:26 PM, Manasi Bopardikar [EMAIL PROTECTED] wrote: Hi, Just wanted to show you a small piece of code I have written.Are there any apparent issues here? package TWiki::Plugins::DumbPlugin; use strict; use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC ); $VERSION = '0.1'; $RELEASE = '0.1'; $SHORTDESCRIPTION = 'Dumb plugin that does nothing at all'; $NO_PREFS_IN_TOPIC = 0; $pluginName = 'DumbPlugin'; sub initPlugin { my( $topic, $web, $user, $installWeb ) = @_; TWiki::Func::registerTagHandler( 'HELLOWORLD', \_HELLOWORLD ); TWiki::Func::registerTagHandler( 'HELLOSOMEONE', \_HELLOSOMEONE ); return 1; } sub _HELLOWORLD{ my($session, $params, $theTopic, $theWeb) = @_; return(Hello World); } sub _HELLOSOMEONE { my($session, $params, $theTopic, $theWeb) = @_; my $defaulttext = $params-{_DEFAULT} || ''; my $someoneelse = $params-{someoneelse} || ''; my $yetanother = $params-{yetanother} || ''; my $text = ''; $text .= $defaulttext if $defaulttext; $text .= and if ($text $someoneelse); $text .= $someoneelse if $someoneelse; $text .= and if ($text $yetanother ); $text .= $yetanother if $yetanother; $text = Hello . $text; return $text; } Thanks and Regards, Manasi Bopardikar|s/w Engineer|Persistent SystemsLtd (+91)(020)(30234497)|9371059891 [EMAIL PROTECTED] DISCLAIMER == This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. Yes, The last line in a perl module should be 1; Regards, Amit Saxena
How to create a timezone converter application in Perl !
Hi all, Recently I came across a scenario where I need to convert the time from one timezone to another. Though that time, I used few websites for the same but I want to know how to do the same in Perl. The text below will give the kind of input output my program requires. Basically I want the end user to specify the from and to timezones along with the from time. The output should be to time. Note :- I don't want to use databases for the same. From :- http://www.timezoneconverter.com 10/1/2008 6:00:00 PM(-10 hours, 30 minutes) *06:00:00 p.m. Wednesday October 1, 2008* in *US/Centralhttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *04:30:00 a.m. Thursday October 2, 2008* in *Asia/Calcuttahttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 8:00:00 PMCentral ==IST?? *08:00:00 p.m. Wednesday October 1, 2008* in *US/Centralhttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *06:30:00 a.m. Thursday October 2, 2008* in *Asia/Calcuttahttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 8:00:00 AM (-10 hours, 30 minutes) *08:00:00 a.m. Wednesday October 1, 2008* in *US/Centralhttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *06:30:00 p.m. Wednesday October 1, 2008* in *Asia/Calcuttahttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 10:00:00 AM Central ==IST?? *10:00:00 a.m. Wednesday October 1, 2008* in *US/Centralhttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *08:30:00 p.m. Wednesday October 1, 2008* in *Asia/Calcuttahttp://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * From :- http://www.timeanddate.com/ 9/25/2008 6:00:00 PM(-12 hours, 30 minutes) Thursday, September 25, 2008 at 01:00:00http://www.timeanddate.com/worldclock/meetingdetails.html?year=2008month=9day=25hour=1min=0sec=0p1=234p2=771Wed 6:00 PM *Thu 6:30 AM 9/25/2008 9:00:00 PMPacific ==IST?? Thursday, September 25, 2008 at 04:00:00http://www.timeanddate.com/worldclock/meetingdetails.html?year=2008month=9day=25hour=4min=0sec=0p1=234p2=771Wed 9:00 PM *Thu 9:30 AM Thanks Regards, Amit Saxena
Re: How to create a timezone converter application in Perl !
On Fri, Sep 26, 2008 at 7:39 PM, Rob Dixon [EMAIL PROTECTED] wrote: Amit Saxena wrote: Recently I came across a scenario where I need to convert the time from one timezone to another. Though that time, I used few websites for the same but I want to know how to do the same in Perl. The text below will give the kind of input output my program requires. Basically I want the end user to specify the from and to timezones along with the from time. The output should be to time. Note :- I don't want to use databases for the same. From :- http://www.timezoneconverter.com 10/1/2008 6:00:00 PM(-10 hours, 30 minutes) *06:00:00 p.m. Wednesday October 1, 2008* in *US/Central http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *04:30:00 a.m. Thursday October 2, 2008* in *Asia/Calcutta http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 8:00:00 PMCentral ==IST?? *08:00:00 p.m. Wednesday October 1, 2008* in *US/Central http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *06:30:00 a.m. Thursday October 2, 2008* in *Asia/Calcutta http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 8:00:00 AM (-10 hours, 30 minutes) *08:00:00 a.m. Wednesday October 1, 2008* in *US/Central http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *06:30:00 p.m. Wednesday October 1, 2008* in *Asia/Calcutta http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * 10/1/2008 10:00:00 AM Central ==IST?? *10:00:00 a.m. Wednesday October 1, 2008* in *US/Central http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=US/Central * converts to *08:30:00 p.m. Wednesday October 1, 2008* in *Asia/Calcutta http://www.timezoneconverter.com/cgi-bin/zoneinfo.tzc?s=defaulttz=Asia/Calcutta * From :- http://www.timeanddate.com/ 9/25/2008 6:00:00 PM(-12 hours, 30 minutes) Thursday, September 25, 2008 at 01:00:00 http://www.timeanddate.com/worldclock/meetingdetails.html?year=2008month=9day=25hour=1min=0sec=0p1=234p2=771 Wed 6:00 PM *Thu 6:30 AM 9/25/2008 9:00:00 PMPacific ==IST?? Thursday, September 25, 2008 at 04:00:00 http://www.timeanddate.com/worldclock/meetingdetails.html?year=2008month=9day=25hour=4min=0sec=0p1=234p2=771 Wed 9:00 PM *Thu 9:30 AM What have you written so far? Rob I think the gmail have expanded the links / URLs. I am pasting the email below :- Recently I came across a scenario where I need to convert the time from one timezone to another. Though that time, I used few websites for the same but I want to know how to do the same in Perl. The text below will give the kind of input output my program requires. Basically I want the end user to specify the from and to timezones along with the from time. The output should be to time. Note :- I don't want to use databases for the same. From :- http://www.timezoneconverter.com 06:00:00 p.m. Wednesday October 1, 2008 in US/Central converts to 04:30:00 a.m. Thursday October 2, 2008 in Asia/Calcutta 08:00:00 p.m. Wednesday October 1, 2008 in US/Central converts to 06:30:00 a.m. Thursday October 2, 2008 in Asia/Calcutta 08:00:00 a.m. Wednesday October 1, 2008 in US/Central converts to 06:30:00 p.m. Wednesday October 1, 2008 in Asia/Calcutta 10:00:00 a.m. Wednesday October 1, 2008 in US/Central converts to 08:30:00 p.m. Wednesday October 1, 2008 in Asia/Calcutta Thanks Regards, Amit Saxena
Re: 32 bit computation problems with Perl !
On Tue, Sep 16, 2008 at 5:04 PM, John W. Krahn [EMAIL PROTECTED] wrote: Amit Saxena wrote: Hi all, Hello, In the following code, the value of $string in last two cases is not printed correctly. Please let me know what i am missing over here. *# cat l3.pl* #! /usr/bin/perl $ONE_BYTE_RANGE = 256; A one byte range is 0 to 255 so 256 is 1 bit more than one byte. $TWO_BYTE_RANGE = 65536; Same here, you are one bit over the two byte range. $THREE_BYTE_RANGE = 4294967296; $THREE_BYTE_RANGE_1 = 4294967295; A three byte range is 0 to 16777215. What you have there is a _four_ byte range plus one. If you have a 32 bit computer then the largest integer that perl can use is 4294967295. $string = sprintf( %d, %d , hex( 9A ), $ONE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d, hex( 9A ) - $ONE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d , %d, hex( BB76 ), $TWO_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d, hex( BB76 ) - $TWO_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %ld , %ld , hex(98EAB), $THREE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %ld, hex(98EAB) - $THREE_BYTE_RANGE ) ; print ( String = $string \n ); $string = sprintf( %ld, (hex(98EAB) - $THREE_BYTE_RANGE_1 - 1) ) ; print ( String = $string \n ); *# perl l3.pl* String = 154, 256 String = -102 String = 47990 , 65536 String = -17546 String = 626347 , -1 String = -2147483648 String = -2147483648 What numbers did you expect would be printed? John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ What my doubt is why the output of following two statements is same :- $string = sprintf( %ld, hex(98EAB) - $THREE_BYTE_RANGE ) ; print ( String = $string \n ); $string = sprintf( %ld, (hex(98EAB) - $THREE_BYTE_RANGE_1 - 1) ) ; print ( String = $string \n ); That also raises another question, does the perl also has a concept of signed integer representation like C. Regards, Amit Saxena
Re: 32 bit computation problems with Perl !
On Tue, Sep 16, 2008 at 7:07 PM, John W. Krahn [EMAIL PROTECTED] wrote: Amit Saxena wrote: On Tue, Sep 16, 2008 at 5:04 PM, John W. Krahn [EMAIL PROTECTED] wrote: Amit Saxena wrote: In the following code, the value of $string in last two cases is not printed correctly. Please let me know what i am missing over here. *# cat l3.pl* #! /usr/bin/perl $ONE_BYTE_RANGE = 256; A one byte range is 0 to 255 so 256 is 1 bit more than one byte. $TWO_BYTE_RANGE = 65536; Same here, you are one bit over the two byte range. $THREE_BYTE_RANGE = 4294967296; $THREE_BYTE_RANGE_1 = 4294967295; A three byte range is 0 to 16777215. What you have there is a _four_ byte range plus one. If you have a 32 bit computer then the largest integer that perl can use is 4294967295. $string = sprintf( %d, %d , hex( 9A ), $ONE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d, hex( 9A ) - $ONE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d , %d, hex( BB76 ), $TWO_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %d, hex( BB76 ) - $TWO_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %ld , %ld , hex(98EAB), $THREE_BYTE_RANGE ); print ( String = $string \n ); $string = sprintf( %ld, hex(98EAB) - $THREE_BYTE_RANGE ) ; print ( String = $string \n ); $string = sprintf( %ld, (hex(98EAB) - $THREE_BYTE_RANGE_1 - 1) ) ; print ( String = $string \n ); *# perl l3.pl* String = 154, 256 String = -102 String = 47990 , 65536 String = -17546 String = 626347 , -1 String = -2147483648 String = -2147483648 What numbers did you expect would be printed? What my doubt is why the output of following two statements is same :- $string = sprintf( %ld, hex(98EAB) - $THREE_BYTE_RANGE ) ; print ( String = $string \n ); $string = sprintf( %ld, (hex(98EAB) - $THREE_BYTE_RANGE_1 - 1) ) ; print ( String = $string \n ); Because the expression hex(98EAB) - $THREE_BYTE_RANGE_1 - 1 is evaluated as ( hex(98EAB) - $THREE_BYTE_RANGE_1 ) - 1 and not as hex(98EAB) - ( $THREE_BYTE_RANGE_1 - 1 ) as you probably intended, so it appears that subtracting 1 from a number that has overflowed/underflowed is not affecting the total. (This may be a bug in Perl, I don't know.) $ perl -le' $THREE_BYTE_RANGE = 4_294_967_296; $THREE_BYTE_RANGE_1 = 4_294_967_295; print join , hex( 98EAB ), $THREE_BYTE_RANGE, hex( 98EAB ) - $THREE_BYTE_RANGE; print join , hex( 98EAB ), $THREE_BYTE_RANGE_1 - 1, ( hex( 98EAB ) - $THREE_BYTE_RANGE_1 ) - 1; print join , hex( 98EAB ), $THREE_BYTE_RANGE_1 - 1, hex( 98EAB ) - ( $THREE_BYTE_RANGE_1 - 1 ); ' 626347 4294967296 -4294340949 626347 4294967294 -4294340949 626347 4294967294 -4294340947 That also raises another question, does the perl also has a concept of signed integer representation like C. The pack()/unpack()/printf()/sprintf() formats are based on C data types and have signed and unsigned representations. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Are you working on 64 bit system ? Regards, Amit Saxena
Fetching n number of records at a time in Perl DBI !
Hi all, I am looking for a fetch function to fetch n number of records at a time in Perl DBI ! fetchrow_hashref fetches one row at a time whereas fetchall_hashref fetches all the rows at a time. The requirement is to get 100 records at a time (in array or hash) before printing it into the output file. I don't want to use following style ;- my $count=0; while ($href1 = $sth-fetchrow_hashref()) { my @arr1 = (); $count = $count + 1; %arr1 = %$href1; if ($count == 100) { # print to the output file print PTR %arr1; } } Thanks Regards, Amit Saxena
Re: Fetching n number of records at a time in Perl DBI !
On Thu, Sep 11, 2008 at 8:01 PM, Dr.Ruud [EMAIL PROTECTED][EMAIL PROTECTED] wrote: jm schreef: there is a LIMIT option for the SELECT statement that will return the number of records you desire. $sth = $dbh-prepare(select whatever from table optional WHERE arguments LIMIT desired number of records); $sth-execute(); while ($vars ...) = $sth-fetchrow_array()) { } # or whatever syntax best suits your preferences That won't always work as you expect it. You need to give values for the ORDER BY and OFFSET and LIMIT, but between queries there can be new rows inserted or deleted, so you might get the same row again, or miss new ones. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ What about the scenario when the table is accessed in a read-only mode ? Also I want to know whether the subsequent calls to fetchrow_array will actually fetch the next LIMIT records or the current LIMIT one. Regards, Amit Saxena
Re: Fetching n number of records at a time in Perl DBI !
On Fri, Sep 12, 2008 at 12:01 AM, Dr.Ruud [EMAIL PROTECTED][EMAIL PROTECTED] wrote: Amit Saxena schreef: Dr.Ruud: jm: there is a LIMIT option for the SELECT statement that will return the number of records you desire. $sth = $dbh-prepare(select whatever from table optional WHERE arguments LIMIT desired number of records); $sth-execute(); while ($vars ...) = $sth-fetchrow_array()) { } # or whatever syntax best suits your preferences That won't always work as you expect it. You need to give values for the ORDER BY and OFFSET and LIMIT, but between queries there can be new rows inserted or deleted, so you might get the same row again, or miss new ones. [snipped signature, one should never quote signatures] What about the scenario when the table is accessed in a read-only mode ? Things get mixed up now. One technique is the one documented in the DBI documentation (as I quoted), the other technique is doing repeated queries with changing offset. Both have their uses. Also I want to know whether the subsequent calls to fetchrow_array will actually fetch the next LIMIT records or the current LIMIT one. The query that you prepared for a fetchrow_arrayref() with a $max_records parameter can have a SQL-LIMIT value, but that value is of course normally greater than the $max_records value. The $max_records value is the number of rows (or chunk size) that you want to work on at the same time. The SQL-LIMIT value is the maximum number of rows that the query returns (in total). -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ I have made a sample program to test this using my old program :- Old Program :- # cat test1.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # Example PERL DBI/DBD Oracle Example on Oracle 10g use DBI; my $dbname = ; ## DB Name from tnsnames.ora my $user = ; my $passwd = ; Connect to the database and return a database handle $dbh = DBI-connect(dbi:Oracle:${dbname}, $user, $passwd); if($dbh){ print(Connected as user $user\n); } else { print(Failed to connect!\n); exit; } Prepare and Execute a SQL Statement Handle my $sth = $dbh-prepare(SELECT * FROM employee); $sth-execute(); # [ # [ 1, 2, 3 ], # [ 4, 5, 6 ], # [ 7, 8, 9 ] # ] $recordref = $sth-fetchall_arrayref(); foreach $recordrow (@{$recordref}) { $col1 = ${$recordrow}[0]; $col2 = ${$recordrow}[1]; $col3 = ${$recordrow}[2]; $col4 = ${$recordrow}[3]; $col5 = ${$recordrow}[4]; $col6 = ${$recordrow}[5]; print \n[$col1][$col2][$col3][$col4][$col5][$col6]; } print(Select Done!...); Disconnect if($dbh-disconnect){ print(Disconnected\n); } else { print(Failed to disconnect\n); } # Output of Old Program :- # perl test1.pl Connected as user [100][Wilson][Clrk][1700][][10] [101][Smith][Slsm][2500][1300][40] [103][Reed][Anlt][3500][][30] [105][Watson][Mngr][4500][0][30] [109][Allen][Mngr][3800][8000][40] [110][Turner][Clrk][1800][][50] [200][Chen][Mngr][2900][][10] [210][Ramirez][Mngr][3650][][50] [213][McDonnel][Clrk][1625][][60] [214][Simpson][Drvr][825][][60] [215][Di Salvo][Spvr][2700][][60] [220][Schwartz][Slsm][4250][5300][40]Select Done!...Disconnected New Program :- # cat test3.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # Example PERL DBI/DBD Oracle Example on Oracle 10g use DBI; my $dbname = ; ## DB Name from tnsnames.ora my $user = ; my $passwd = ; Connect to the database and return a database handle $dbh = DBI-connect(dbi:Oracle:${dbname}, $user, $passwd); if($dbh){ print(Connected as user $user\n); } else { print(Failed to connect!\n); exit; } Prepare and Execute a SQL Statement Handle my $sth = $dbh-prepare(SELECT * FROM employee); $sth-execute(); # [ # [ 1, 2, 3 ], # [ 4, 5, 6 ], # [ 7, 8, 9 ] # ] my $max_rows = 4; # $recordref = $sth-fetchall_arrayref(); # while ($recordref = $sth-fetchall_arrayref(undef, $max_rows)) #while($row = shift(@$recordref) || shift(@{$recordref=$sth-fetchall_arrayref(undef, $max_rows)})) { } while (my $recordref = shift(@$rowcache) || shift ( @{$rowcache = $sth-fetchall_arrayref(undef, $max_rows)} )) { foreach $recordrow (@{$recordref}) { $col1 = ${$recordrow}[0]; $col2 = ${$recordrow}[1]; $col3 = ${$recordrow}[2]; $col4 = ${$recordrow}[3]; $col5 = ${$recordrow}[4]; $col6 = ${$recordrow}[5]; print \n[$col1][$col2][$col3][$col4][$col5][$col6]; } print \n\n; }; print(\nSelect Done!...\n); Disconnect if($dbh-disconnect){ print(Disconnected\n); } else { print(Failed to disconnect\n); } # Output of New program
Re: Fetching n number of records at a time in Perl DBI !
On Fri, Sep 12, 2008 at 9:36 AM, Raja Vadlamudi [EMAIL PROTECTED] wrote: On Thu, Sep 11, 2008 at 11:12 PM, Amit Saxena [EMAIL PROTECTED]wrote: On Fri, Sep 12, 2008 at 12:01 AM, Dr.Ruud [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Amit Saxena schreef: Dr.Ruud: jm: there is a LIMIT option for the SELECT statement that will return the number of records you desire. $sth = $dbh-prepare(select whatever from table optional WHERE arguments LIMIT desired number of records); $sth-execute(); while ($vars ...) = $sth-fetchrow_array()) { } # or whatever syntax best suits your preferences That won't always work as you expect it. You need to give values for the ORDER BY and OFFSET and LIMIT, but between queries there can be new rows inserted or deleted, so you might get the same row again, or miss new ones. [snipped signature, one should never quote signatures] What about the scenario when the table is accessed in a read-only mode ? Things get mixed up now. One technique is the one documented in the DBI documentation (as I quoted), the other technique is doing repeated queries with changing offset. Both have their uses. Also I want to know whether the subsequent calls to fetchrow_array will actually fetch the next LIMIT records or the current LIMIT one. The query that you prepared for a fetchrow_arrayref() with a $max_records parameter can have a SQL-LIMIT value, but that value is of course normally greater than the $max_records value. The $max_records value is the number of rows (or chunk size) that you want to work on at the same time. The SQL-LIMIT value is the maximum number of rows that the query returns (in total). -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ I have made a sample program to test this using my old program :- Old Program :- # cat test1.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # Example PERL DBI/DBD Oracle Example on Oracle 10g use DBI; my $dbname = ; ## DB Name from tnsnames.ora my $user = ; my $passwd = ; Connect to the database and return a database handle $dbh = DBI-connect(dbi:Oracle:${dbname}, $user, $passwd); if($dbh){ print(Connected as user $user\n); } else { print(Failed to connect!\n); exit; } Prepare and Execute a SQL Statement Handle my $sth = $dbh-prepare(SELECT * FROM employee); $sth-execute(); # [ # [ 1, 2, 3 ], # [ 4, 5, 6 ], # [ 7, 8, 9 ] # ] $recordref = $sth-fetchall_arrayref(); foreach $recordrow (@{$recordref}) { $col1 = ${$recordrow}[0]; $col2 = ${$recordrow}[1]; $col3 = ${$recordrow}[2]; $col4 = ${$recordrow}[3]; $col5 = ${$recordrow}[4]; $col6 = ${$recordrow}[5]; print \n[$col1][$col2][$col3][$col4][$col5][$col6]; } print(Select Done!...); Disconnect if($dbh-disconnect){ print(Disconnected\n); } else { print(Failed to disconnect\n); } # Output of Old Program :- # perl test1.pl Connected as user [100][Wilson][Clrk][1700][][10] [101][Smith][Slsm][2500][1300][40] [103][Reed][Anlt][3500][][30] [105][Watson][Mngr][4500][0][30] [109][Allen][Mngr][3800][8000][40] [110][Turner][Clrk][1800][][50] [200][Chen][Mngr][2900][][10] [210][Ramirez][Mngr][3650][][50] [213][McDonnel][Clrk][1625][][60] [214][Simpson][Drvr][825][][60] [215][Di Salvo][Spvr][2700][][60] [220][Schwartz][Slsm][4250][5300][40]Select Done!...Disconnected New Program :- # cat test3.pl #!/usr/bin/perl ##!/u01/app/oracle/product/10.1.0/db_1/perl/bin/perl # Example PERL DBI/DBD Oracle Example on Oracle 10g use DBI; my $dbname = ; ## DB Name from tnsnames.ora my $user = ; my $passwd = ; Connect to the database and return a database handle $dbh = DBI-connect(dbi:Oracle:${dbname}, $user, $passwd); if($dbh){ print(Connected as user $user\n); } else { print(Failed to connect!\n); exit; } Prepare and Execute a SQL Statement Handle my $sth = $dbh-prepare(SELECT * FROM employee); $sth-execute(); # [ # [ 1, 2, 3 ], # [ 4, 5, 6 ], # [ 7, 8, 9 ] # ] my $max_rows = 4; # $recordref = $sth-fetchall_arrayref(); # while ($recordref = $sth-fetchall_arrayref(undef, $max_rows)) #while($row = shift(@$recordref) || shift(@{$recordref=$sth-fetchall_arrayref(undef, $max_rows)})) { } while (my $recordref = shift(@$rowcache) || shift ( @{$rowcache = $sth-fetchall_arrayref(undef, $max_rows)} )) { foreach $recordrow (@{$recordref}) { $col1 = ${$recordrow}[0]; $col2 = ${$recordrow}[1]; $col3 = ${$recordrow}[2]; $col4 = ${$recordrow}[3]; $col5 = ${$recordrow}[4
Re: Fetching n number of records at a time in Perl DBI !
On Fri, Sep 12, 2008 at 9:53 AM, dan [EMAIL PROTECTED] wrote: On Thu, 11 Sep 2008 17:23:22 +0530, Amit Saxena [EMAIL PROTECTED] wrote: Hi all, I am looking for a fetch function to fetch n number of records at a time in Perl DBI ! I had to do this kind of thing to implement 'record paging' in Gtk2::Ex::DBI. The way I did it was in a couple of steps. 1) Run a query to *only* select primary key(s) from the records that you want 2) Store these primary keys in an array 3) Assemble a query to select the fields you want, and add your primary key(s) to the where clause So your final query would look like: select field_1, field_2, field_3 from some_table where some_primary_key in ( 1, 5, 10, 24, 30 ); ... and the numbers in the 'in ( )' bit would be populated from your array of primary keys. This is a nice DB-neutral way of doing it, and you don't get bitten by the DB server returning rows in a different order each time you run a query, possibly returning duplicates across different 'pages' ( DB servers don't guarantee the order that records are returned in unless you explicitly add an 'order by' clause and list all relevant columns ). Feel free to check out Gtk2::Ex::DBI for a complete working example. I've considered moving this functionality out into a generic record paging module, but haven't ever really had the time to do it. The only issue with this approach is that two queries needs to be run for the same. Considering the tables containing 1 million (and more) rows, this two pass approach will not be good. What others say ? Regards, Amit Saxena
Re: Fetching n number of records at a time in Perl DBI !
On Fri, Sep 12, 2008 at 10:52 AM, dan [EMAIL PROTECTED] wrote: On Fri, 12 Sep 2008 10:24:58 +0530, Amit Saxena wrote: The only issue with this approach is that two queries needs to be run for the same. Considering the tables containing 1 million (and more) rows, this two pass approach will not be good. What others say ? It's precisely because you can have so many rows that this 2-pass approach is best. In the 1st query, where all your 'where' conditions are processed, the database server does all the collecting of the rows ( well, primary keys ) that you want in 1 go. Once it's done, that's it ... you only do it once. Also because you're only fetching the primary keys and not the entire recordset, it's actually quite fast to transfer the keyset from the DB server to the client. Also your memory requirements on the DB server are MUCH lower as the server only has to hold a list of primary keys ( numeric ) in memory, instead of all the rest of the columns as well, which could contain strings and other memory-hungry columns. I did extensive testing ( MySQL, SQL Server, SQLite ) before going down this path, trust me ... Then you've got an array of indexes ( the keyset ) that you send to the DB server ( ie in the where clause ), and it makes accessing all pages *very* fast, as you're using the primary keys to fetch data. If you don't do it like this, you're making the DB server reprocess your complicated where clause each time. If you're got millions of records, this is incredibly CPU memory intensive for the DB server, and not feasible if you've got multiple clients hitting the DB server. Also as noted in my previous post, if you're not very careful with sorting, you'll can end up getting duplicate records. Anyway, if you find a better way, I'd like to hear it :) Dan Thanks Dan for the detailed explanation :-). The benefits of the two-pass approach is now clear to me. Regards, Amit Saxena
Difference between perl -w and use warnings in perl !
Hi all, What's the difference between perl -w and use warnings in perl ? If there is no difference, then the use warnings can be removed from the perl programs and replace them with perl -w.of removing use warnings. Thanks Regards, Amit Saxena
Re: Difference between perl -w and use warnings in perl !
On Mon, Sep 1, 2008 at 6:39 PM, Rob Dixon [EMAIL PROTECTED] wrote: Amit Saxena wrote: What's the difference between perl -w and use warnings in perl ? If there is no difference, then the use warnings can be removed from the perl programs and replace them with perl -w.of removing use warnings. The difference is that the pragma is lexically scoped (it affects only statements in the block of code where it appears) and it allows fine control over warning categories. So for instance you could write use strict; use warnings; my $s = 'xxx'; { no warnings qw/substr uninitialized/; my $sub = substr $s, 10, 10; print $sub; } which is impossible with the command line switch, which is either on or off. See perldoc perllexwarn for details. And I'm wondering why you would want to remove 'use warnings' from your program? Rob It's a requirement from the client side, according to them as only good code gets submitted from development environment to the production environment, they don't need use warnings and also perl -w as well. It might sound strange to you, (I also got surprised when I came to know about it), but that's the truth ! Regards, Amit Saxena
Re: return sorted hashes from subroutines
On Fri, Aug 29, 2008 at 5:10 PM, Pedro Soto [EMAIL PROTECTED] wrote: Hi, I am trying to write script to retrieve info from a file that looks like: col1 col2col3 A5 10 A5 10 A5 11 A6 8 A7 9 B5 8 B6 9 what i need is to get for each (non redundant) value from column 1, the corresponding non redundant values from column 2 and 3. e.g: For A (col 1), I want 5 -10, 5-11 and 6-8. For B: 5-8 and 6-9. I wrote a script to get rid of the redundant values using hashes and subroutines and it worked. However I still need to compare the elements from col2 and col3 with other values. To do this I want to sort the data, but I am struggling to sort the hash. It prints what I want but only if ask it to print within the subroutine (line 29). I do not know how to return a hash with the sorted values. I hope someone could help me out with this. The code is below: #! usr/local/bin/perl use warnings; use strict; my %db_del; my %std_dup; open(IN,file.csv) || die; while (IN) { my @temp=split/,/; push (@{$db_del{$temp[0]}}, $temp[1].\t.$temp[2]); } NONRE(%db_del,%std_dup); foreach my $e(%db_dup) { foreach my $l (@{$db_dup{$e}}) { print $e,$l,$std_dup{$l}\n; #does not print $std_dup{$l} }} sub## sub NONRE { my %hash; my %seen; my @uniq; my %st; %hash = @_; foreach my $k (sort keys%hash) { foreach my $item(@{$hash{$k}}) { push(@uniq,$item) unless $seen{$item}++; } foreach my $item(@uniq) { my @stend =split/\t/,$item; $st{$stend[0]}= $stend[1]; } @{$hash{$k}}= sort {$a = $b} keys%st; foreach my $f(keys%hash){ foreach my $l(@{$hash{$f}}) { print $f,$l,$st{$l} ok\n;# it prints OK } } } @uniq =(); %seen =(); return(%hash,%st); } My solution to do the same :- *# cat l1.pl* #! /usr/bin/perl use strict; use warnings; use Data::Dumper; my $gh; open (PTR, redundant_values.txt) or die Cannot open input file : $!; my $str; while ($str = PTR) { chomp $str; $str =~ s/ +/ /g; my ($a, $b, $c) = split (/ /, $str); # $gh = # { # 1 = {1 = 2}, # a = {b = c}, # p = {q = r} # }; # # $gh-{'$a'}-${'$b'} = $c; print ==$str\n; if (! exists ${gh}-{$a}-{$b}) { ${gh}-{$a}-{$b} = $c; # ${${${gh}}{$a}}{$b} = $c; print Dumper($gh); # print Data::Dumper-Dump($gh); } } close (PTR); print Original File :-\n; open (PTR, redundant_values.txt) or die Cannot open input file : $!; while ($str = PTR) { chomp $str; print $str\n; } close (PTR); print New File :-\n; my ($a, $b); while (($a, $b) = each (%{${gh}})) { my ($c, $d); while (($c, $d) = each (%{${b}})) { print $a,$c,$d\n; } } *#* *# perl l1.pl* ==A 5 1 $VAR1 = { 'A' = { '5' = '1' } }; ==A 5 1 ==A 5 1 ==A 6 1 $VAR1 = { 'A' = { '6' = '1', '5' = '1' } }; ==A 7 2 $VAR1 = { 'A' = { '6' = '1', '7' = '2', '5' = '1' } }; ==B 5 8 $VAR1 = { 'A' = { '6' = '1', '7' = '2', '5' = '1' }, 'B' = { '5' = '8' } }; ==B 6 9 $VAR1 = { 'A' = { '6' = '1', '7' = '2', '5' = '1' }, 'B' = { '6' = '9', '5' = '8' } }; Original File :- A5 1 A5 1 A5 1 A6 1 A7 2 B5 8 B6 9 New File :- A,6,1 A,7,2 A,5,1 B,6,9 B,5,8 *#* Regards, Amit Saxena
Re: Perl and vi (not vim) , ctags like feature in Perl !
On Mon, Aug 25, 2008 at 9:03 PM, anders [EMAIL PROTECTED] wrote: On 25 Aug, 16:32, [EMAIL PROTECTED] (Amit Saxena) wrote: Hi all, - I am using Perl 5.8.4 and vi (not vim) on Solaris 9. While developing my Perl programs, I have to open two sessions one for my vi session and another where I run my perl programs. Moreover, in some scenarios, I have to open a sqlplus session to access Oracle 10g. Shifting between the sessions is tough sometimes. Is there a possibility where I can customize vi for some shortcuts for at least running Perl programs or accessing sqlplus session ? - Is there a ctags like facility for Perl as well ? Thanks Regards, Amit Saxena There is a serverprogram called Screens it can handle multiple screens and let you switch between, On VI you could enter :! to get a shell, test your program and CTRL-D back to the VI, this is my way, maby there is easy steps... // Anders -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Though I don't know much about creating shortcuts in vi but is it possible to create a shortcut in vi (something like epp for execute perl program ) which will take current file as an input, exit temporarily to the shell and once ENTER is pressed, returns to the original program ? Regards, Amit Saxena
Perl and vi (not vim) , ctags like feature in Perl !
Hi all, - I am using Perl 5.8.4 and vi (not vim) on Solaris 9. While developing my Perl programs, I have to open two sessions one for my vi session and another where I run my perl programs. Moreover, in some scenarios, I have to open a sqlplus session to access Oracle 10g. Shifting between the sessions is tough sometimes. Is there a possibility where I can customize vi for some shortcuts for at least running Perl programs or accessing sqlplus session ? - Is there a ctags like facility for Perl as well ? Thanks Regards, Amit Saxena
About the error message in Perl : Missing right curly braces
Hi all, I want to know the best approach that should be used to find the extra curly brace when any Perl program aborts with the error message as Missing right curly braces. Though the error message is simple enough to suggest that there is an extra curly brace in the Perl program, but it specifies the line number as the last line of the program. If the program is very big, matching all the properly nested curly braces and finding out the mismatched one takes lots of effort and time. It happened with me yesterday when I was working with a perl code of around 3000 lines long and it took me nearly 1.5 hours to find out the exact line where the problem is. Thanks Regards, Amit Saxena
Re: About the error message in Perl : Missing right curly braces
On Thu, Aug 21, 2008 at 2:23 PM, Stewart Anderson [EMAIL PROTECTED] wrote: -Original Message- From: Amit Saxena [mailto:[EMAIL PROTECTED] Sent: 21 August 2008 08:56 To: Perl Cc: Amit Saxena Subject: About the error message in Perl : Missing right curly braces Hi all, I want to know the best approach that should be used to find the extra curly brace when any Perl program aborts with the error message as Missing right curly braces. Though the error message is simple enough to suggest that there is an extra curly brace in the Perl program, but it specifies the line number as the last line of the program. If the program is very big, matching all the properly nested curly braces and finding out the mismatched one takes lots of effort and time. It happened with me yesterday when I was working with a perl code of around 3000 lines long and it took me nearly 1.5 hours to find out the exact line where the problem is. [Stewart Anderson] I usually go back to where I was last editing. I do regular syntax checks to see if I missed anything as I'm going too. Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Assuming you are getting the buggy code for the first time and you need to track which line contains that curly brace which is causing that problem, what your modified approach be ? This is exactly the same scenario which I have faced just now. Thanks Regards, Amit Saxena
Re: About the error message in Perl : Missing right curly braces
On Thu, Aug 21, 2008 at 2:44 PM, Stewart Anderson [EMAIL PROTECTED] wrote: -- *From:* Amit Saxena [mailto:[EMAIL PROTECTED] *Sent:* 21 August 2008 10:01 *To:* Stewart Anderson *Cc:* Perl *Subject:* Re: About the error message in Perl : Missing right curly braces On Thu, Aug 21, 2008 at 2:23 PM, Stewart Anderson [EMAIL PROTECTED] wrote: -Original Message- From: Amit Saxena [mailto:[EMAIL PROTECTED] Sent: 21 August 2008 08:56 To: Perl Cc: Amit Saxena Subject: About the error message in Perl : Missing right curly braces Hi all, I want to know the best approach that should be used to find the extra curly brace when any Perl program aborts with the error message as Missing right curly braces. Though the error message is simple enough to suggest that there is an extra curly brace in the Perl program, but it specifies the line number as the last line of the program. If the program is very big, matching all the properly nested curly braces and finding out the mismatched one takes lots of effort and time. It happened with me yesterday when I was working with a perl code of around 3000 lines long and it took me nearly 1.5 hours to find out the exact line where the problem is. [Stewart Anderson] I usually go back to where I was last editing. I do regular syntax checks to see if I missed anything as I'm going too. Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Assuming you are getting the buggy code for the first time and you need to track which line contains that curly brace which is causing that problem, what your modified approach be ? This is exactly the same scenario which I have faced just now. Thanks Regards, Amit Saxena Hi, Most decent editors have a match brace function - google for the function for the editor you use? HTH I am using vi on Solaris. I can also use % in command mode for vi to match parenthesis and curly braces. However this approach results in lots of matching open brace against the close one etc when majority of the lines in the code contains curly braces (through references etc). Though I must admit that this was the approach I used yesterday, but I have to do this for 3k lines of code. Regards, Amit Saxena
Re: About the error message in Perl : Missing right curly braces
On Thu, Aug 21, 2008 at 5:23 PM, Peter Scott [EMAIL PROTECTED] wrote: On Thu, 21 Aug 2008 14:31:07 +0530, Amit Saxena wrote: Assuming you are getting the buggy code for the first time and you need to track which line contains that curly brace which is causing that problem, what your modified approach be ? Load the code into Emacs. Ensure cperl-mode is enabled. Mark the whole buffer (control-space at the beginning, then move point to the end). Execute M-x indent-region, Look to see where the indentation goes off. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ How can we enable indentation with in vi (and not vim) on Solaris for Perl Code ? Regards, Amit Saxena
Oraperl and DBI !
I have read somewhere in web that Oraperl is a wrapper around DBI. To the best of my knowledge, I think that's not true because of following reasons :- 1. Oraperl was much older compared to DBI 2. Not all DBI functions are available with Oraperl ! Please confirm. Thanks Regards, Amit Saxena
Complete program execution trace in Perl !
Hello all, Is there a way through which I can get following information while executing a perl program :- - Details of every argument passed to the subroutine and the value (if any) returned from the subroutine - All the SQL statements printed (something like DBI_trace in perl) - Last but not the least, variable value (if possible) affected at various statements The reason why I need this is I need to inspect a very long perl program which in turn uses few perl modules. If I will get some facility like what I have asked in the email, I will just execute the program to get all the information in a very big log file. Still inspecting the program execution pattern like the order in which the subroutines are called, the arguments passed and returned and the SQL statement executed will help me to locate places where all I need to do the modification. The other alternative is to use debugger but that's highly interactive. Though Perl DBI allows embedding Perl DBI trace statements at various places in the program, it requires changes to the complete program which I don't want to do. Thanks Regards, Amit Saxena
Re: DBI equivalent of Oraperl ora_titles function !
On Tue, Aug 5, 2008 at 6:06 PM, Peter Scott [EMAIL PROTECTED] wrote: On Tue, 05 Aug 2008 09:38:41 +0530, Amit Saxena wrote: What's the DBI equivalent of Oraperl ora_titles function ? I need it because I want to get the titles (column names) of a select query into an array without fetching the row values from the database. I believe you want the NAME statement handle attribute: http://search.cpan.org/~timb/DBI-1.607/DBI.pm#NAME_(array-ref,_read-only)http://search.cpan.org/%7Etimb/DBI-1.607/DBI.pm#NAME_%28array-ref,_read-only%29 -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Peter, Thanks, it worked for me ! Regards, Amit Saxena
DBI equivalent of Oraperl ora_titles function !
Hi all, What's the DBI equivalent of Oraperl ora_titles function ? I need it because I want to get the titles (column names) of a select query into an array without fetching the row values from the database. Thanks Regards, Amit Saxena
Re: Substitution within an html page
On Sat, Aug 2, 2008 at 3:12 AM, David Allender [EMAIL PROTECTED] wrote: Hello all, I've been trying multiple different ways, but I am still unable to have the output that i am looking for. What I'm trying to do is change certain text in an html file. How would i go about doing that successfully? what i know is that you call open such as open(HTML, /path); and from there use the s/// operator, but I really cant get anything to change in my files. the string I would like to search for would be something like value=src1 (without quotes) and i would want to replace it with something like /home/user/test/ (without quotes) Any help is appreciated. Thanks -David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Try this code fragment (have not run it though) :- #/usr/bin/perl use warnings; use strict; open (HTMLFILE, /tmp/test.html) or die 'Can't open HTML FILE /tmp/test.html : $!\n\n; open (HTMLFILE1, /tmp/test1.html) or die 'Can't create HTML FILE /tmp/test1.html : $!\n\n; my $str; while (chomp($str = HTMLFILE)) { $str =~ s/value=src/\/home\/usr\/test\//g; print HTMLFILE1 $str\n; } close (HTMLFILE1); close (HTMLFILE); Regards, Amit Saxena
Code not working as desired !
Hi all, I am trying to make a perl code which would read a matrix (basically an array which contains references to other arrays) and initialize a hash with the first value of each dereferenced array acting as a key and remaining elements as values using references. The source code and output are mentioned below :- Source Code - [root]# cat k1.pl #! /usr/bin/perl use strict; use warnings; my @arr = ( [1, 2, 3, a, b], [4, 5, 6, c, d], [7, 8, 9, e, f] ); my @arr1; my %h; my $a; my $key1; my $i; my $n; print Matrix is as follows :- \n; foreach $a (@arr) { print Row = @{$a}\n; @arr1 = ; $n = @{$a}; for ($i=1; $i=$n-1;$i++) { $arr1[$i-1] = ${$a}[$i]; } $h{ ${$a}[0] } = [EMAIL PROTECTED]; } print Hash is as follows :- \n; foreach $key1 (keys %h) { print Key - [$key1] : Value - [EMAIL PROTECTED]; } print \n; [root]# Actual Output --- [root]# perl k1.pl Matrix is as follows :- Row = 1 2 3 a b Row = 4 5 6 c d Row = 7 8 9 e f Hash is as follows :- Key - [4] : Value - [8 9 e f] Key - [1] : Value - [8 9 e f] Key - [7] : Value - [8 9 e f] [root]# Expected Output --- [root]# perl k1.pl Matrix is as follows :- Row = 1 2 3 a b Row = 4 5 6 c d Row = 7 8 9 e f Hash is as follows :- Key - [4] : Value - [5 6 c d] Key - [1] : Value - [2 3 a b] Key - [7] : Value - [8 9 e f] [root]# Thanks Regards, Amit Saxena
Difference between = and = in Perl !
Hi all, I could be a very basic question but I am unable to find any answers on internet. What's the difference between = and = in Perl ? To the best of my knowledge, = means greater than or equal to and = is just used instead of comma to distinguish between key and values while assigning a hash. I am unable to justify the output of the following program (for = operator) $ cat y.pl #! /usr/bin/perl use warnings; use strict; my $i = 6; if ($i = 5) { print \nInside If; } else { print \nInside Else; } print \n===; if ($i = 5) { print \nInside If; } else { print \nInside Else; } print \n; $ perl y.pl Useless use of private variable in void context at y.pl line 26. Inside If === Inside If [EMAIL PROTECTED]:~]$ Thanks Regards Amit Saxena
Re: how to convert data available from excel to hash?
On Mon, Jul 21, 2008 at 11:22 AM, Sivasakthi [EMAIL PROTECTED] wrote: Hi all, How to convert data available from excel sheet to hash table? Thanks, Siva -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ If the data is not very complicated, convert the excel into .csv file and then read that file line by line to convert into a hash. Regards, Amit Saxena
Re: Strange sorting, need some help
On Mon, Jul 21, 2008 at 2:11 AM, Rob Dixon [EMAIL PROTECTED] wrote: Tobias Eichner wrote: I'm currently dealing with a sample program I try to understand. Here it is: --- #!/usr/bin/perl use strict; use warnings; use diagnostics; # Array to sort my @unsortiert = qw(Z A z a 19 91); # Print array to sort print @unsortiert; print \n; # Print positions of unsorted array (0 to last entry #) my @pos_unsortiert = (0..$#unsortiert); print @pos_unsortiert; print \n; # Start sorting my @pos_sortiert = sort({$unsortiert[$a] cmp $unsortiert[$b]} (0..$#unsortiert)); print @pos_sortiert; print \n; my @sortiert; for (0..$#unsortiert) { $sortiert[$_] = $unsortiert[$pos_sortiert[$_]]; print \n$unsortiert[$_] was element $_\t\tand is now element $pos_sortiert[$_].; }; print \n\nThis is the sorted result: @sortiert; print \n; --- For unknown reason sorting fails when running the program using an array that contains numbers. I'm aware that I try here to compare numbers with the cmp operator, but although warnings have be enabled, Perl doesn't get angry about. So when you run this script as above, you'll notice that the sorting is done correctly, but the positions aren't. More strangly when sorting an array of strings only, anything is correct (soring and positions output). Maybe some of you can give me a hint, since I want to understand why it doesn't work when using numbers ? If you were using the = operator to compare non-numeric strings you would get a warning, but any scalar value is a valid string so you will get no warnings if you compare numeric values with the cmp operator. Sorting numbers as strings causes them to be sorted in dictionary order, which is different from numeric order if the numbers have the same number of digits. So 2 is greater than 11 in the same way that 'B'is greater than 'AA'. I'm not clear what you mean by the sorting is done correctly, but the positions aren't, but I hope that helps? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Rob That means you want to mention that always use cmp instead of = for any kind of data, numeric or non-numeric. Regards, Amit Saxena
Re: DBI error
On Tue, Jul 22, 2008 at 9:18 AM, Panda-X [EMAIL PROTECTED] wrote: Hi, I've got this error, anything I can do ? Can't locate auto/DBI/data_source.al in @INC Code : use DBI; my @dataSource = DBI - data_source ( mysql ) ; and if I change the as this : use DBI; my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ; I got this error : Can't connect to data source 'dbi:mysql' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at quickPerl.pl line 8 I have MySQL server installed and it works well with other applications. Thanks for help! Is it because you have not specified the database name in the following connect statement :- use DBI; my $dbh = DBI - connect ( dbi:mysql, $adm, $pass ) ; Regards, Amit Saxena
Re: Parsing XML
On Sat, Jul 19, 2008 at 6:44 AM, Rob Dixon [EMAIL PROTECTED] wrote: Epanda wrote: Epanda wrote: I would like to know if we can parse XML with regexp faster than with an MSXML or Xerces library ? I just want to parse an XML and I have seen that the XML!!Parser of Perl based on Expat is the most faster ofth world, I don't know Twig. My XML is classical : ?xml version='1.0' encoding='ISO-8859-1'? !DOCTYPE CONF_INST SYSTEM dtd_conf_inst.dtd ROOT_NODE VERS=1.0 NODE1 TAG=VD/N1 SERIAL=3HHE C IDOM/ID VALSAT/VAL /C C IDTPS/ID VAL3E+01/VAL /C /NODE1 /ROOT_NODE but can be very big. XML::Twig is built on Expat, and is especially good at processing large files one element at a time instead of loading the whole file into memory first. For instance, if your data consists of multiple independent NODE1 elements XML::Twig can be set up to process them individually and so save memory. Take a look here http://www.xmltwig.com/xmltwig/ But if you are hoping to write something that is faster than MSXML or Xerces you may be unsucessful. Perl also has XML::LibXML and XML::Xerces modules as well if you want to try those. What do you need to do with the data? It may be possible with regular expressions if the data is consistently formatted. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi ! I am using use XML::SAX::ParserFactory . I want to know whether it's a better alternative than suggested so far in this thread or not ? If not, please suggest. Regards, Amit Saxena
Re: Foreach with array of hashes
On Sat, Jul 19, 2008 at 2:45 PM, Bobby Jafari [EMAIL PROTECTED] wrote: Hi all, I am getting a syntax error with the following code: Line 10: @snmpSessions = (%snmpSession1, %snmpSession2); Line 11: foreach %snmpSession (@snmpSessions) Line 12: { Line 13:# The following is call to my own subroutine that has been tested and it works (:-) Line 14:ethernetGlobalMode (\%snmpSession); Line 15: } I get the following error: syntax error at C:\SVN\qa-tests\2084\testcase\TC-Ether-Type-Test.pl line 11, near foreach %snmpSession syntax error at C:\SVN\qa-tests\2084\testcase\TC-Ether-Type-Test.pl line 15, near } Execution of C:\SVN\qa-tests\2084\testcase\TC-Ether-Type-Test.pl aborted due to compilation errors. Thanks for your comments and feedback. Regards, Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi ! The following statement is causing the problems :- *Line 10: @snmpSessions = (%snmpSession1, %snmpSession2);* The statement should be [EMAIL PROTECTED] = (\%snmpSession1, \%snmpSession2);* Remember, arrays can contain only scaler values so in case you want contents of some hashes etc in an array, you must use references. Having said that, the following lines * ** Line 11: foreach %snmpSession (@snmpSessions) Line 12: { Line 13:# The following is call to my own subroutine that has been tested and it works (:-) Line 14:ethernetGlobalMode (\%snmpSession); Line 15: }* should change to * Line 11: foreach $snmpS (@snmpSessions) Line 12: { Line 13:# The following is call to my own subroutine that has been tested and it works (:-) Line 14:ethernetGlobalMode ($snmpS); Line 15: }* Let us know in case you are facing more problems. Regards, Amit Saxena
Re: How can we Install Perl in Windows
On Thu, Jul 17, 2008 at 12:53 PM, Sivasakthi [EMAIL PROTECTED] wrote: Hi all, How can we install perl in windows system? Let me know the steps or direct me right document.. before that is it necessary to installing the IIS? Thanks, Siva -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi ! Use ActiveState of windows . http://www.activestate.com/Products/activeperl/index.mhtml . Note :- I just don't want to be controversial or raise controversies but I feel that before posting the query on the mailing list, at least proper efforts should be spent on the search engine of your choice. I am not discouraging anybody from posting there queries on perl, all the members in this mailing list are here to learn and simultaneously help others but everybody expects the person who raises the query to do some initial basic searching on the internet. Have said that, in case you have more queries, send it to the mailing list. Regards, Amit Saxena
Re: How can we Install Perl in Windows
On Thu, Jul 17, 2008 at 6:55 PM, yitzle [EMAIL PROTECTED] wrote: No one here believes in the CygWin package? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ I feel for Perl on windows platform, more people are using it with ActiveState rather than Cygwin. I might be wrong though. Regards, Amit Saxena
Re: A newbie question - line number inside the script
On Wed, Jul 16, 2008 at 3:52 PM, Amit Koren [EMAIL PROTECTED] wrote: Hi list. I'm a newbie to Perl, (and to this mailing list) :) There's a task i was given, in which it is necessary to get the number of the current executing line/command - inside the script itself. Can someone assist please ? Thanks in advance, Amit. If you are referring to process ID by number, you can use $$ for that. Regards, Amit Saxena
Re: Compare Excel file
I still say, converting the excel files in .csv format and then comparing is not a bad solution. Regards, Amit Saxena On Thu, Jul 17, 2008 at 9:43 AM, Sivasakthi [EMAIL PROTECTED] wrote: Dr.Ruud wrote: Sivasakthi schreef: Is it possible to compare two excel file by using Perl? Yes, see for example `perldoc -f -s`. Maybe you are interested in the diff of the two binaries? Or do you want to check whether the data in the two files are presented in exactly the same colors and font sizes? http://www.catb.org/~esr/faqs/smart-questions.htmlhttp://www.catb.org/%7Eesr/faqs/smart-questions.html Thanks for your reply.. I wanted to check the data present in two excel file have exactly the same value. The second file have some rows position changed. but the columns are equal. I dont want to check the colors and font size, I wanted to check the data are exactly present. please guide me . Thanks, Siva -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Compare Excel file
What about this approach where we convert two excel files in .csv format and then compare those two files ? Regards, Amit Saxena On Tue, Jul 15, 2008 at 4:33 PM, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Sivasakthi wrote: Gunnar Hjalmarsson wrote: Sivasakthi wrote: Is it possible to compare two excel file by using Perl? Yes. Let me know how to do that.. or direct me to right document. I have never done it, but I think I'd follow these steps: 1. Decide in what way they are going to be compared, and what the output should look like. 2. Check out CPAN for suitable modules. http://search.cpan.org/search?query=excel+parse 3. Write code. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
fetching encrypted passwords for oracle username in Perl !
Hi Instead of hard-coded passwords in my source code or an input file, I would like to enable some sort of encryption through some keys for all the usernames in Oracle 10g. Please let me know how to do that with Perl DBI ? Thanks Regards, Amit Saxena
Re: fetching encrypted passwords for oracle username in Perl !
No Jeff, that's not what I am looking for. Let me explain the scenario in detail. My application users Perl-DBI and at present I have encoded my username and password in the perl program. Now, as my testing is over, I would like to publish this code to my team so that they can checkout the latest version from the pvcs and use it. The problem comes now only. I want the application to use there username/password pair instead of mine. That's the reason, I don't want to put my hardcoded username and password in my file. There could be some ways as a way around which I have listed below but none of them is the best :- - *Put username and password through environment variable* : bad idea to use environment variables here - *Ask at runtime* : I would like my application to run without user input at runtime. Regards, Amit Saxena On Mon, Jul 14, 2008 at 3:02 PM, Jeff Peng [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 4:40 PM, Amit Saxena [EMAIL PROTECTED] wrote: Hi Instead of hard-coded passwords in my source code or an input file, I would like to enable some sort of encryption through some keys for all the usernames in Oracle 10g. Please let me know how to do that with Perl DBI ? You focus on how to store datas into database, not on how to encrypt datas, is it? DBI can do that, see `perldoc DBI`. -- Regards, Jeff. - [EMAIL PROTECTED]
Re: Perl script doesnt behave well
Try pasting some input record for which the output is not coming. If the record contains confidential data, you can mask the data. Regards, Amit Saxena On Mon, Jul 14, 2008 at 3:43 PM, luke devon [EMAIL PROTECTED] wrote: Hi, I am using perl script to handle some function of squid redirector program . Actually its working fine. But after some time , that functions goes off. That's meant VALUE-A doesnt comes in to the request. I checked the DB , it also fine. CPU also nothing Can some body help me please ? #!/usr/bin/perl use DBI; use strict; use warnings; # no buffered output, auto flush $|=1; my ($dbh,$sth,$dbargs,$VALUE-A,$VALUE-B,$query); $dbh = DBI-connect(dbi:mysql:List;localhost,root,) || Error Opening DataBase: $DBI::errstr\n; if (!$dbh-err()) { while (STDIN) { chomp; my ($url, $x, $ip) = split(/ /); $ip = substr($ip, 0, (length($ip)-2)); $query = SELECT * from ACCOUNT where someField = ' . $ip .' order by xxx_yyy desc; $sth = $dbh-prepare($query); $sth-execute(); if (my $ref = $sth-fetchrow_hashref()) { $VALUE-A = $ref-{'CallingStationId'}; $VALUE-B = $ref-{'AcctSessionId'}; }else{ $VALUE-A = NA; } if (!($url =~ m#xxx#)) { if ($url =~ m#\?#) { $url .= xxx= . $VALUE-A . - . $ip . - . $VALUE-B; } else { $url .= ?xxx= . $VALUE-A . - . $ip . - . $VALUE-B; } print $url.\n; } else { print \n; } } }else { print \n; } $sth-finish(); $dbh-commit(); $dbh-disconnect(); Many thanks Luke Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: Perl script doesnt behave well
modifiy $sth-execute(); with $num_rows = $sth-execute() or die Unable to call execute $!\n\n; Regards, Amit Saxena On Mon, Jul 14, 2008 at 6:30 PM, luke devon [EMAIL PROTECTED] wrote: could you please direct me how could I implement those steps in to the code ? - Original Message From: Thomas Bätzler [EMAIL PROTECTED] To: Perl beginners@perl.org Cc: luke devon [EMAIL PROTECTED] Sent: Monday, July 14, 2008 16:05:21 Subject: RE: Perl script doesnt behave well luke devon [EMAIL PROTECTED] asked: I am using perl script to handle some function of squid redirector program . Actually its working fine. But after some time , that functions goes off. That's meant VALUE-A doesnt comes in to the request. Is it possible that your script has lost the connection to the database? From what I see of your code you don't check the return value from $sth-execute. You really should do that, and possibly use $dbh-ping() at the head of the while loop to determine wether you need to reconnect to your database. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: how to read the formatted data from the file?
#! /usr/bin/perl use warnings; use strict; open (PTR1, filename.txt) or die Unable to open file filename.txt : $!\n\n; while (chomp ($str = PTR1)) { sscanf($str, %5d %11.2f, $data1, $data2); # do whatever processing. } close (PTR1); Regards, Amit Saxena On Mon, Jul 14, 2008 at 8:23 PM, vikingy [EMAIL PROTECTED] wrote: Hi all, There is a file created likes this: open File file.txt or die $!; foreach .. .. { printf File %5d %11.2f\n, $data1,data2; } close File; and my question is, how to read these data follow the same format as %5d %11.2f' from this file again? thanks in advance! 2008-07-14 The Key Lab of Complex Systems and Intelligence Science, Institute of Automation, Chinese Academy of Sciences.
Re: how to read the formatted data from the file?
oops I was thinking along C lines on that one ! Please remove sscanf part from the loop. Regards Amit Saxena On Tue, Jul 15, 2008 at 2:29 AM, Rob Dixon [EMAIL PROTECTED] wrote: Brad Baxter wrote: Amit Saxena wrote: #! /usr/bin/perl use warnings; use strict; open (PTR1, filename.txt) or die Unable to open file filename.txt : $!\n\n; while (chomp ($str = PTR1)) { sscanf($str, %5d %11.2f, $data1, $data2); # do whatever processing. } close (PTR1); Regards, Amit Saxena sscanf()? Hehe I missed that one! Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Get Clients Windows Logon ID
Using environment variables to find username are risky ! Is there any API available for the same ? Thanks Regards, Amit Saxena On Fri, Jul 11, 2008 at 8:39 PM, Rob Dixon [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Hi All, Can you please advice me how to get the Clients' windows logon user name in perl? $ENV{USERNAME} Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Count of number of rows returned in delete / update sql in Perl DBI ?
Hi ! I also referred to the CPAN page before posting this query. It's already working for me with Oracle 10g on Perl 5.8.4 on RHEL. Though somewhere on the web, I read a post by some perl developer that execute for him is not returning the number of rows affected. That's why, I asked the query. Regards, Amit Saxena On Thu, Jul 10, 2008 at 8:12 PM, Rob Dixon [EMAIL PROTECTED] wrote: Amit Saxena wrote: Hi all, I want to know how to get the count of number of rows returned in delete / update sql in Perl DBI ? I have ready some articles on the internet and it states that the execute function returns the number of rows affected though it's not confirmed to work for all the database. Is there any solution which will surely work on all databases ? I suggest that you simply test to make sure that it works on your database. 'execute' will return -1 if the number of rows affected is unknown. Rob
Certification in Perl
Hi I would like to know is there any Perl specific certification which I can look forward to ? Note :- I was not sure to which mailing list should this query be sent, please let me know in case I have to send it to a different group / mailing list etc. Regards, Amit Saxena
Freelance opportunities in Perl !
Hi I am looking for freelance opportunities in Perl. I have an IT experience in Perl, Shell Scripting, Pro*C, UNIX and SQL. Apart from my main job, I can devote around 10 hours per week initially, which I can adjust it to more as more and more work comes. Apart from me, some of my friends are also interested in the same. Note :- I was not sure to which mailing list should this query be sent, please let me know in case I have to send it to a different group / mailing list etc. Regards, Amit Saxena
Re: how to read the last line of a file directly?
Hi Though I am not very sure, but can we use inbuilt seek function in perl ? Regards, Amit Saxena On Mon, Jul 7, 2008 at 12:39 AM, Rob Dixon [EMAIL PROTECTED] wrote: loody wrote: I try to read the last line of a file directly instead of using while() or something else to read each line until undef bumped to me. If you know some build-in functions or another modules for me to use, please help me. Like this. Both Fcntl and Tie::File are standard modules. HTH, Rob use strict; use warnings; use Fcntl; use Tie::File; tie my @file, 'Tie::File', 'filename', mode = O_RDONLY or die $!; print $file[-1]; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: removing '*' from *****STAFF*****
Hi Rajnikant, That removes the character * for everywhere whereas the requirement is only to remove from the beginning and trailing parts of the string. Regards, Amit Saxena On Thu, Jul 3, 2008 at 11:19 AM, Rajnikant [EMAIL PROTECTED] wrote: Try out this, my $stuff = '*STAFF*'; $stuff =~ s/\*//g; Print $stuff; Regards, Rajnikant Jachak -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Thursday, July 03, 2008 10:38 AM To: Perl Beginners Subject: Re: removing '*' from *STAFF* Manasi Bopardikar wrote: Does anyone know how do I remove the beginning and the trailing * from *STAFF* my $stuff = '*STAFF*'; s/^\*+//, s/\*+$// for $stuff; Or if you want to remove all * regardless of where in the string they are located: $stuff =~ tr/*//d; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ DISCLAIMER == This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: about Zlib
Hi Rajnikant, Just couple of things regarding your email format etc :- 1. It's suggested not to use official email if in the mailing list (I prefer it the same way). 2. Even if you use it, make sure that the email which you send does not have copyright statements etc as it adds to the mail space. This thing was brought to notice by one member in the IPSec mailing list. I don't want to create a controversy over here though. I would like to know other people's opinion over here. Also in case this needs to be raised in a seperate mailing list, let me know. I will do that. Regards, Amit Saxena On Wed, Jul 2, 2008 at 12:43 PM, Rajnikant [EMAIL PROTECTED] wrote: Thanks for replying Jeff. But can we use Zlib for same? Rajnikant Jachak | Software Engg | Persistent Systems Limited [EMAIL PROTECTED] | Cell: +91 9822204088 | Tel: +91 (20) 3023 2479 Persistent Systems - Innovations in software product design,development and delivery - www.persistentsys.com -Original Message- From: Jeff Peng [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 02, 2008 12:37 PM To: Rajnikant Cc: beginners@perl.org Subject: Re: about Zlib On Wed, Jul 2, 2008 at 12:50 PM, Rajnikant [EMAIL PROTECTED] wrote: I want to uncompress *.gz and *.tar on linux box. So is there any package which will do it for me? Can we use Zlib to do same? Search and use a module from CPAN, that will make things fast. like: http://search.cpan.org/~kane/Archive-Tar-1.38/lib/Archive/Tar.pmhttp://search.cpan.org/%7Ekane/Archive-Tar-1.38/lib/Archive/Tar.pm -- Regards, Jeff. - [EMAIL PROTECTED] DISCLAIMER == This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Re: Re: @INC and cross-platform path usage
Hi I still doubt whether * unshift (@INC,$librarydir);* works or not. To the best I have read the articles and tutorials, @INC can't be updated in this way. You have to either use one of the options below :- - *PERL5LIB* environment variable - using *use lib ()* construct - use *Find::Bin* module What others say ? Regards, Amit Saxena On Wed, Jul 2, 2008 at 2:32 PM, Tobias Eichner [EMAIL PROTECTED] wrote: I wrote the following script that fits my needs; maybe someone finds it useful, maybe someone finds an error in it (if so, let me know - I tested it on OS X and Win XP): use File::Spec; my ($volume,$softwaredir,$librarydir); ($volume,$softwaredir) = File::Spec-splitpath(__FILE__); $librarydir = File::Spec-catpath($volume,$softwaredir,'libraries'); unshift (@INC,$librarydir); @Gunnar Hjalmarsson: Sure, but note that you need to put it in a BEGIN block if you want it to happen at compile time. I'd suggest that you take this opportunity to check out the lib pragma. perldoc lib It's not rocket science. ;-) Will do so for sure :-) Thanks again for your help with this. __ Gesendet von Yahoo! Mail. Dem pfiffigeren Posteingang. http://de.overview.mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: simplify a path
Hi The code would be something like this :- [root@ ~]# cat t.pl #!/usr/bin/perl $str = /a/b/./c/../d; $str1 = $str; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; $str1 =~ s/([^\/]+)\/\.\.\/([^\/]+)/$2/g; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; $str1 =~ s/\.\/([^\/]+)/$1/g; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; print \nHave a nice day !!!\n; [root@ ~]# perl t.pl str = [/a/b/./c/../d] str1 = [/a/b/./c/../d] --- str = [/a/b/./c/../d] str1 = [/a/b/./d] --- str = [/a/b/./c/../d] str1 = [/a/b/d] --- Have a nice day !!! Regards, Amit Saxena On Wed, Jul 2, 2008 at 7:03 PM, Chen Yue [EMAIL PROTECTED] wrote: Hi I have a file containing UNIX-styled Path in each line. But the path is simplified enough. Some of them has .. and . in the middle, such as /a/b/./c/../d. Now I want to simplify each Path according to Unix tradition. /a/b/./c/../d-/a/b/d The only way I could think out is to split the path and reconstruct them in reverse order. But I don't think it is a smart solution. Is there a quick way to employ regexp or a library to fix this? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: simplify a path
Hi I agree that the code has some flaws in that. Infact immediately after posting my solution, I thought of your test case only. If I will get some time, I will work on the same and let you know. Thanks for the feedback. Regards, Amit Saxena On Wed, Jul 2, 2008 at 8:08 PM, Chen Yue [EMAIL PROTECTED] wrote: Hi Amit The code really works but with a tiny flaw. If the path is /a/b/../../c, the result would be /a/../c rather than /c. So I need to loop to clean up the dot-dot if tied up Thank you for the suggestion Hi The code would be something like this :- [root@ ~]# cat t.pl #!/usr/bin/perl $str = /a/b/./c/../d; $str1 = $str; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; $str1 =~ s/([^\/]+)\/\.\.\/([^\/]+)/$2/g; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; $str1 =~ s/\.\/([^\/]+)/$1/g; print \nstr = [$str]; print \nstr1 = [$str1]; print \n---; print \nHave a nice day !!!\n; [root@ ~]# perl t.pl str = [/a/b/./c/../d] str1 = [/a/b/./c/../d] --- str = [/a/b/./c/../d] str1 = [/a/b/./d] --- str = [/a/b/./c/../d] str1 = [/a/b/d] --- Have a nice day !!! Regards, Amit Saxena On Wed, Jul 2, 2008 at 7:03 PM, Chen Yue [EMAIL PROTECTED] wrote: Hi I have a file containing UNIX-styled Path in each line. But the path is simplified enough. Some of them has .. and . in the middle, such as /a/b/./c/../d. Now I want to simplify each Path according to Unix tradition. /a/b/./c/../d-/a/b/d The only way I could think out is to split the path and reconstruct them in reverse order. But I don't think it is a smart solution. Is there a quick way to employ regexp or a library to fix this? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: substitution
Why don't use perl s operator with e option ? $str =~ s/([^ ]+)/$hash{\1}/ge Regards, Amit Saxena On Tue, Jul 1, 2008 at 3:57 AM, Brad Baxter [EMAIL PROTECTED] wrote: On Jun 30, 4:20 pm, [EMAIL PROTECTED] (Epanda) wrote: Hi, I have to do a substitution of a pattern in a text file, So you know about perl -i, right? this pattern is a key of a hash table previously set. so I want to replace my pattern by the corresponding value of the key in the hash table ex : file : n1 n22 hash : n1 = wordA n2 = wordB n22 = wordN I want to have filenew like this : file : wordA wordN with a single %s/pattern/hashpattern/g expression Thanks for helping You mean like this? perl -i.bak -pe '%h = (n1=wordA, n22=wordN); for $x (keys %h){ s/\Q $x/$h{$x}/g }' data.txt -- Brad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Array problem
use $*dbh*-*quote*($str) On Tue, Jul 1, 2008 at 4:59 AM, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Beyza wrote: I have an array which has strings like; John's House Bla bla; etc, When I use them in an SQL query, perl gives an error. So, I need to put escape character for every special character. Is there any quick way to do it? perldoc -f quotemeta -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: substitution
Hi John, I am not only expanding a variable but also using that expanded variable as a key to ultimately find the value. That's why I need e. Secondly, inside text that is to be substituted, I can use \1 as well. And moreover, for this, I don't need double quotes. If i purposefully incorporate double quotes, then I need $1. Regards, Amit Saxena On Tue, Jul 1, 2008 at 4:19 PM, John W. Krahn [EMAIL PROTECTED] wrote: Amit Saxena wrote: Why don't use perl s operator with e option ? $str =~ s/([^ ]+)/$hash{\1}/ge You don't need the /e option to interpolate a variable in a double quoted string and you should use $1 instead of \1 inside a double quoted string: $str =~ s/([^ ]+)/$hash{$1}/g John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: @INC and cross-platform path usage
You can also set the environment variable PERL5LIB to whatever directory that contains your custom library files. Regards, Amit Saxena On Tue, Jul 1, 2008 at 6:32 PM, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Tobias Eichner wrote: I have created a Perl library that I want to use with my programs (via require). However the Perl library should be placed at a sub-folder of the working directory (the place where the program runs). For example: /my/custom/path/ is the location of the program. /my/custom/path/libraries/ is the location where I want to place my Perl libraries in. How can I implement this considering that my Perl program will run on different platforms with different ways of writing paths ? Would it work to use require ./libraries/mylib.pl on all platforms (*nix, Windows, Mac, something else) ? I don't think so. Not sure if paths can be used overall with require (not tried it yet). My idea would be to use the standard module File::Spec to add the path to my libraries to @INC. For example: my $mylibpath = File::Spec-rel2abs(libraries/); unshift(@INC,$mylibpath); Is this a cross-platform compatible way ? Or is there a better solution ? Both those methods assume that the path to the directory where the program resides equals the current working directory. That's often the case, but not always. Some would suggest the use of the FindBin module. It does the right thing, but unfortunately it is known to be buggy. In a similar case I chose to simply say use lib 'libraries'; and tell the users to manually change 'libraries' to the full path when necessary. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: about perl module uninstallation
Is there a way to convert the perl packages from CPAN to binary packages in linux like rpm etc. This way, it's easy for installation, uninstallation of the modules. On Tue, Jul 1, 2008 at 9:52 PM, Randal L. Schwartz [EMAIL PROTECTED] wrote: Telemachus == Telemachus [EMAIL PROTECTED] writes: Telemachus On Jun 22, 3:32 pm, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: Note: the CPAN Shell and the CPAN-PLUS Shell are not package managers, and have no uninstall capability. Telemachus Cpan-plus can uninstall, but only if you installed the module with Telemachus cpan-plus originally. I thought that was one of the main benefits Telemachus of cpanp over cpan (the command not the CPAN). Well, both CPAN and CPANP can *delete* what they *install*, except that they don't really manage to notice that something they installed was also used by some other package. Which means that using either CPAN or CPANP's option to delete what I installed means you could damage *another* package that happened to share the same filename, and yes it does happen. A proper package manager would have required human intervention to manage the conflicting ownership of the shared file. And once the human is involved, and ownership established, proper uninstallation is possible. I tried not to have to explain all this in my previous post, but since you challenged my brief explanation, here's the details, yet again. Please, just trust me when I say things in the future. It's faster. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: user id validation
What if before running this perl code, I modify the 'USER' environment variable ? I have not tried like that but I feel it can be done because the environment variables are not restricted. Assuming that works, then any user can just reset the environment variable to any one among the allowed ones and the script will work. I feel the better way is to use system command and call whoami or id command. Regards, Amit Saxena On Wed, Jul 2, 2008 at 10:30 AM, Rajnikant [EMAIL PROTECTED] wrote: I think Work around for this is, My $usr = $ENV { USER }; If ($usr eq userA) Go get it Else Access restricted. Rajnikant Jachak | Software Engg | Persistent Systems Limited [EMAIL PROTECTED] | Cell: +91 9822204088 | Tel: +91 (20) 3023 2479 Persistent Systems - Innovations in software product design,development and delivery - www.persistentsys.com -Original Message- From: Richard Lee [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 02, 2008 10:18 AM To: Perl Beginners Subject: user id validation I am just wondering how to validate a user who is using the script?? I wanted to allow only user below to be able to user the script and was thinking about userA(userid: 1077) userB(userid: 1088) userC(userid: 1099) so, inside of script, I would put, unless ( $userid =~ /1077|1088|1099/ ) { print You are not authorized to use this\n; } but I am not sure how to come up w/ $userid ? how do I find out what the userid of person who is using the script? Is there specific perl command for that? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ DISCLAIMER == This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: I could not do it with matlab could perl do it?
$str= 'GO:022 0.00312066574202497 9/2884 1/597 0.0023457 NAmitotic spindle elongation YBL084C ' (undef, undef, undef, $var1, $var2) = split (/\s*/, $str); On Wed, Jun 25, 2008 at 1:20 PM, fadlyemen [EMAIL PROTECTED] wrote: Hi All I could not do it with matlab could perl do it? I appreciate if I have solution for this problem I try to extract two columns from a text file(8 columns) with variable number of headerlines, and variable line length. below is one line of my data S= 'GO:022 0.00312066574202497 9/2884 1/597 0.0023457 NA mitotic spindle elongation YBL084C ' How could I get column 4 , 5 using perl. Fadl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How can I translate it back to @ sign.
Try $email =~ s/[[:cntrl:]]/@/g; instead of $email =~ s/!/@/g; Infact try this in the entire file. Note :- This is on the assumption that there are no other control characters in the input file. On Fri, Jun 27, 2008 at 2:51 AM, Aruna Goke [EMAIL PROTECTED] wrote: David Romero wrote: use a regular expression my $email = 'user!dominio.com'; $email =~ s/!/@/g; ###Result [EMAIL PROTECTED] http://www.troubleshooters.com/codecorn/littperl/perlreg.htm On Thu, Jun 26, 2008 at 1:35 PM, Aruna Goke [EMAIL PROTECTED] wrote: hi, i have the this log from my sms gateway, however, the inverted exclamation mark was sent from the smsc as @. 2008-06-26 17:22:35 SMS request sender:+2342019122 request: 'maruna¡ontng.com,test,Love my test message' file answer: '' 2008-06-26 17:27:17 Receive SMS [SMSC:caxt] [SVC:] [ACT:] [BINF:] [from:+2342019122] [to:+2349191] [flags:-1:0:-1:0:-1] [msg:43:maruna!ontng.com,test,Love my test message] [udh:0:] 2008-06-26 17:27:17 SMS request sender:+23422019122 request: 'maruna!ontng.com,test,'Love my test message'file answer: '' 2008-06-26 17:34:15 Receive SMS [SMSC:caxt] [SVC:] [ACT:] [BINF:] [from:+2342019122] [to:+2349191] [flags:-1:0:-1:0:-1] [msg:43:maruna¡ontng.com,test,Love my test message] [udh:0:] I have my script that parse the file and extract as below To: maruna¡ontng.com Subject: test Message: Love my test message sender : [EMAIL PROTECTED] What i want to achieve is to translate the to address back to [EMAIL PROTECTED] instaed of maruna¡ontng.com. when i checked through, i discover that it is inverted exclamation mark with character code 00A1 from unicode(hex) of latin-1 subset. I need this translated to @, any help will be appreciated my script is as below #!/usr/bin/perl use strict; use warnings; use File::Tail; use Mail::Sender; # the access.log is read and the following, recepient is extracted. my $name = /var/log/bulksms/sms_access.log; my ($mailreci, $mailsubj, @sms, $mailmsg, $mailsend, $sendee, $sender, $msg, $domain); $domain = 'ontng.com'; open my $file, '', $name or die could not open $name: $!; $file=File::Tail-new(name=$name, maxinterval=3, adjustafter=5); while (defined($_=$file-read)) { @sms = split/\[/; next unless $sms[6]=~/to:\+2349191\]/; $sendee = $sms[5]; $sendee =~ s/from:\+(\d+)\]/$1/; $sendee = [EMAIL PROTECTED]; $msg = $sms[8]; $msg = (split/:/, $msg)[-1]; $msg =~ s/(\w+)\s?\]/$1/; # i need only sender and $msg ($mailreci, $mailsubj, $mailmsg) = (split/,/, $msg, 3)[0..2]; print To: $mailreci Subject: $mailsubj Message: $mailmsg sender : $sendee\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ its not an exclamation mark but inverted exclammation mark. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Automation
You can even refer to free task schedules for windows on the web. Have a look at http://www.snapfiles.com/freeware/ You also can go for cygwin on Windows. On Mon, Jun 30, 2008 at 8:18 PM, Bob McConnell [EMAIL PROTECTED] wrote: In MS-Windows, take a look at the Task Scheduler to see if it can help. Start-Programs-Accessories-System Tools-Scheduled Tasks Bob McConnell -Original Message- From: Ram [mailto:[EMAIL PROTECTED] Sent: Monday, June 30, 2008 5:03 AM To: beginners@perl.org Subject: Re: Automation Thanks for your information. But here i am using Windows XP operating system Thanks, Ram On Jun 30, 12:57 pm, [EMAIL PROTECTED] (Eko Budiharto) wrote: you can use crontab in linux. On Mon, Jun 30, 2008 at 2:26 PM, Ram [EMAIL PROTECTED] wrote: Hi All, I am begineer to perl language. Want help for the automation of the perl script. Is it possible to run a perl script at defined time interval without cliking over the scipt and using command prompt. I want it run without any GUI. it shoud run automatically at defined time ? Please give your valuable suggestions Thanks in advance. Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- Eko Budiharto- Hide quoted text - - Show quoted text - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How can I translate it back to @ sign.
Hi Aruna The solution my $invexcl = \x{00A1}; my $atsign = \x{0040}; $mailreci =~ s/(\w+)$invexcl(\w+)/$1$atsign$2/g; works fine. However that assumes that you know the control character to be substituted. If the file contains lots of control characters and if the requirement is to remove all of them or to substitute all of them with some ascii character etc, my solution is preferred. By the way, how do you find the octal / hexadecimal code of control character that appears in the file. I use UNIX ob -bc command for the same but even that is also cumbersome if there are many lines and many control charcters. Regards, Amit Saxena On Mon, Jun 30, 2008 at 7:05 PM, Aruna Goke [EMAIL PROTECTED] wrote: Amit Saxena wrote: Try $email =~ s/[[:cntrl:]]/@/g; instead of $email =~ s/!/@/g; Infact try this in the entire file. Note :- This is on the assumption that there are no other control characters in the input file. On Fri, Jun 27, 2008 at 2:51 AM, Aruna Goke [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: David Romero wrote: use a regular expression my $email = 'user!dominio.com http://dominio.com'; $email =~ s/!/@/g; ###Result [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] http://www.troubleshooters.com/codecorn/littperl/perlreg.htm On Thu, Jun 26, 2008 at 1:35 PM, Aruna Goke [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: hi, i have the this log from my sms gateway, however, the inverted exclamation mark was sent from the smsc as @. 2008-06-26 17:22:35 SMS request sender:+2342019122 request: 'maruna¡ontng.com http://ontng.com,test,Love my test message' file answer: '' 2008-06-26 17:27:17 Receive SMS [SMSC:caxt] [SVC:] [ACT:] [BINF:] [from:+2342019122] [to:+2349191] [flags:-1:0:-1:0:-1] [msg:43:maruna!ontng.com http://ontng.com,test,Love my test message] [udh:0:] 2008-06-26 17:27:17 SMS request sender:+23422019122 request: 'maruna!ontng.com http://ontng.com,test,'Love my test message'file answer: '' 2008-06-26 17:34:15 Receive SMS [SMSC:caxt] [SVC:] [ACT:] [BINF:] [from:+2342019122] [to:+2349191] [flags:-1:0:-1:0:-1] [msg:43:maruna¡ontng.com http://ontng.com,test,Love my test message] [udh:0:] I have my script that parse the file and extract as below To: maruna¡ontng.com http://ontng.com Subject: test Message: Love my test message sender : [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] What i want to achieve is to translate the to address back to [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] instaed of maruna¡ontng.com http://ontng.com. when i checked through, i discover that it is inverted exclamation mark with character code 00A1 from unicode(hex) of latin-1 subset. I need this translated to @, any help will be appreciated my script is as below #!/usr/bin/perl use strict; use warnings; use File::Tail; use Mail::Sender; # the access.log is read and the following, recepient is extracted. my $name = /var/log/bulksms/sms_access.log; my ($mailreci, $mailsubj, @sms, $mailmsg, $mailsend, $sendee, $sender, $msg, $domain); $domain = 'ontng.com http://ontng.com'; open my $file, '', $name or die could not open $name: $!; $file=File::Tail-new(name=$name, maxinterval=3, adjustafter=5); while (defined($_=$file-read)) { @sms = split/\[/; next unless $sms[6]=~/to:\+2349191\]/; $sendee = $sms[5]; $sendee =~ s/from:\+(\d+)\]/$1/; $sendee = [EMAIL PROTECTED]; $msg = $sms[8]; $msg = (split/:/, $msg)[-1]; $msg =~ s/(\w+)\s?\]/$1/; # i need only sender and $msg ($mailreci, $mailsubj, $mailmsg) = (split/,/, $msg, 3)[0..2]; print To: $mailreci Subject: $mailsubj Message: $mailmsg sender : $sendee\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] http://learn.perl.org/ its not an exclamation mark but inverted exclammation mark. --To unsubscribe, e-mail: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] mailto:[EMAIL
Re: Perl coding - Reinventing the Wheel ?
I agree with you as well on this ! On Thu, Jun 19, 2008 at 10:37 PM, Chas. Owens [EMAIL PROTECTED] wrote: Build from scratch to teach yourself about things, but use the wheels already invented for real/production work. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. On Jun 19, 2008, at 12:53, Gunwant Singh wrote: Hi all, I have a dilmma for the last few days. I read an article about '10 things every Perl hacker should know' (available here: http://articles.techrepublic.com.com/5100-10878_11-6077064.html). And I was concerned about the point that says NOT to reinvent the wheel. I was just thinking to build up a traversal program for a directory a couple of days ago and then I read this article.Now Perl has so many modules made by 'The Gurus'.And I found one of them File::Find which made my work so easy. I wanted to know , what is your opinion on the same. Should we build up the code from the very scratch - In that way we learn new ways to build up the same code which may help in coding something similar in a better way, or use the modules whenever/wherever they are available. Any suggestions/opinions will be highly appreciated. Cheers, Gunwant Singh. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/