append to beginning of file
Help. How do I append data to the beginning of a file? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: append to beginning of file
Hi. What you should do is write both your new data and the contents of the old file to a new file. Afterwards, you might rename the new file to replace the old one. Like: #!/usr/bin/perl -w open (NEWFILE, ">your new file's name") or die "Couldn't open new file: $!"; print NEWFILE $new_data; # ... and so on ... open (OLDFILE, ")) { print NEWFILE "$line\n"; } close OLDFILE; close NEWFILE; # And now, if you want: rename "your new file's name", "your old file's name"; Sascha At 03:41 15.08.01 -0400, you wrote: >Help. How do I append data to the beginning of a file? > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how many items in a hash?
Bob Showalter <[EMAIL PROTECTED]> writes: > Or, from perldoc perldata: > > If you evaluate a hash in scalar context, it returns false if the hash > is empty. If there are any key/value pairs, it returns true; more > precisely, the value returned is a string consisting of the number of > used buckets and the number of allocated buckets, separated by a > slash. > > print "Empty!\n" unless %myhash; Note that the number of used buckets isn't (necessarily) the same as the number of items in the hash. -- Piers Cawley www.iterative-software.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl/Tk controling widgets
I have been working on three separate Perl/Tk programs and now I would like to have them all called from a single window. I am not sure how to do this without making the three, one. I tried making them modules but the windows are displayed before the main window. I have to then close them before I can start. What is the best way to handle this. Thanks John -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
perl scripts
Hi, I am very new to perl. I am just using the perl script to run this application. I have this perl script in unix and i need to convert it to windows . can anyone help me? The error message that it shows when i run this script is , it cannot identify the "HUP". and i don't know what is that? the script is as the following: #!/usr/local/bin/perl $LOGPATH='D:/apache/apache/logs'; @LOGNAMES=('access_log'); $PIDFILE = 'http://httpd.pid'; $MAXCYCLE = 4; chdir $LOGPATH; # Change to the log directory foreach $filename (@LOGNAMES) { for (my $s=$MAXCYCLE; $s >= 0; $s-- ) { $oldname = $s ? "$filename.$s" : $filename; $newname = join(".",$filename,$s+1); rename $oldname,$newname if -e $oldname; } } kill 'HUP',`cat $PIDFILE`; Pls assist me. Thank you. Disclaimer note: Confidential information may be contained in this e-mail and any files transmitted with it ('Message'). If you are not the addressee indicated in this Message (or responsible for delivery of this Message to such person), you are hereby notified that any dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. In such a case, you should delete this Message immediately and advise the sender by return e-mail. Opinions, conclusions and other information in this Message that do not relate to the official business of Maxis shall be understood as neither given nor endorsed by Maxis. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl scripts
it's in the last line: kill 'HUP',`cat $PIDFILE`; it's a unix command to kill *nix processes... which of course won't work on windows... what is the purpose of using this on windows? it's structure is quite different... hth Jos - Original Message - From: "Rajeswary Santhiran" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 11:44 AM Subject: perl scripts Hi, I am very new to perl. I am just using the perl script to run this application. I have this perl script in unix and i need to convert it to windows . can anyone help me? The error message that it shows when i run this script is , it cannot identify the "HUP". and i don't know what is that? the script is as the following: #!/usr/local/bin/perl $LOGPATH='D:/apache/apache/logs'; @LOGNAMES=('access_log'); $PIDFILE = 'http://httpd.pid'; $MAXCYCLE = 4; chdir $LOGPATH; # Change to the log directory foreach $filename (@LOGNAMES) for (my $s=$MAXCYCLE; $s >= 0; $s-- ) $oldname = $s ? "$filename.$s" : $filename; $newname = join(".",$filename,$s+1); rename $oldname,$newname if -e $oldname; } } kill 'HUP',`cat $PIDFILE`; Pls assist me. Thank you. Disclaimer note: Confidential information may be contained in this e-mail and any files transmitted with it ('Message'). If you are not the addressee indicated in this Message (or responsible for delivery of this Message to such person), you are hereby notified that any dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. In such a case, you should delete this Message immediately and advise the sender by return e-mail. Opinions, conclusions and other information in this Message that do not relate to the official business of Maxis shall be understood as neither given nor endorsed by Maxis. > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
XML::Parser -- Problem with undefined entities in element attributes
Hi there, I've been bumping my head up against this problem all morning now, and can't come up with an answer, maybe someone with XML::Parser experience can help. The XML::Parser documentation doesn't really have any suggestions. Normally you can use the NoExpand method to prevent the parser from expanding entity references in the text. But this doesn't affect entity references that appear in attribute values. Is there any way to handle entity references in attribute values? My problem is I have tags in my xml that contain entity references like this: and XML::Parser generates the following error: undefined entity at line 6, column 33, byte 218: ===^ So obviously ® isn't in the internal set of references, and it is generating an error. I'd like to set up a handler for this condition, rather than having the program die! I have tried setting the ExternEnt handler to handle this case, but it doesn't seem to get triggered in this instance. Any ideas? Mike Michael Kavanagh Internet Development Manager Oxford University Press v:01865 267 452 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XML::Parser -- Problem with undefined entities in element attribu tes
On Wednesday 15 August 2001 12:28, KAVANAGH, Michael wrote: > Is there any way to handle entity references in attribute values? > > My problem is I have tags in my xml that contain entity references like > this: > and XML::Parser generates the following error: > undefined entity at line 6, column 33, byte 218: > So obviously ® isn't in the internal set of references, and it is > generating an error. I'd like to set up a handler for this condition, > rather than having the programthan die! Entity references in attribute values are always a problem in XML::Parser. You can trick the parser in thinking they are defined somewhere in an external DTD by using a fake one but then the entity disappears from the attribute value. The only way I found was to use my own parsing method on the string that the parser recognized as the entire tag. Here is a script that shows you a document that parses (in the __DATA__ section), wht XML:Parser gives you and what a custom parse can get. Note that until Unicode support for regexp is complete (perl 5.8) the custom parser will likely fail for document that include multi-byte characters. One last comment: if you are dealing with XML with Perl you might want to subscribe to theperl-XML mailing list, info at http://listserv.ActiveState.com/mailman/listinfo/perl-xml #!/bin/perl -w use strict; use XML::Parser 2.27; my $p= new XML::Parser( Handlers => { Start => \&display_start_tag }, NoExpand => 1 ); $p->parse( \*DATA); sub display_start_tag { my( $p, $tag, %atts)= @_; # what XML::Parser gives you print "recognized: ", $p->recognized_string(), "\n\n"; print "tag: $tag\n"; foreach my $att (keys %atts) { print " $att: $atts{$att}\n"; } # what you can get ($tag, %atts)= parse_start_tag( $p->recognized_string()); print "\ntag: $tag\n"; foreach my $att (keys %atts) { print " $att: $atts{$att}\n"; } } sub parse_start_tag { my $string= shift; my( $gi, %atts); # get the gi (between < and the first space, / or > character) if( $string=~ s{^<\s*([^\s>/]*)[\s>/]*}{}s) { $gi= $1; } else { die "internal error when parsing start tag $string"; } while( $string=~ s{^([^\s=]*)\s*=\s*(["'])(.*?)\2\s*}{}s) { $atts{$1}= $3; } return $gi, %atts; } __DATA__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: XML::Parser -- Problem with undefined entities in element attribu tes
That is very helpful Michel, thanks. And thanks for the reference to the mailing list... I didn't know about that one. One final follow-up point... Interestingly, in testing this problem, I found that XML::Parser handles ® in the attribute fine, but not, as I said, ®. The ascii value entity seems to be handled ok. Can you confirm that in your experience this is the case generally? Mike -Original Message- From: Michel Rodriguez [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 12:12 PM To: KAVANAGH, Michael; [EMAIL PROTECTED] Subject: Re: XML::Parser -- Problem with undefined entities in element attribu tes On Wednesday 15 August 2001 12:28, KAVANAGH, Michael wrote: > Is there any way to handle entity references in attribute values? > > My problem is I have tags in my xml that contain entity references like > this: > and XML::Parser generates the following error: > undefined entity at line 6, column 33, byte 218: > So obviously ® isn't in the internal set of references, and it is > generating an error. I'd like to set up a handler for this condition, > rather than having the programthan die! Entity references in attribute values are always a problem in XML::Parser. You can trick the parser in thinking they are defined somewhere in an external DTD by using a fake one but then the entity disappears from the attribute value. The only way I found was to use my own parsing method on the string that the parser recognized as the entire tag. Here is a script that shows you a document that parses (in the __DATA__ section), wht XML:Parser gives you and what a custom parse can get. Note that until Unicode support for regexp is complete (perl 5.8) the custom parser will likely fail for document that include multi-byte characters. One last comment: if you are dealing with XML with Perl you might want to subscribe to theperl-XML mailing list, info at http://listserv.ActiveState.com/mailman/listinfo/perl-xml #!/bin/perl -w use strict; use XML::Parser 2.27; my $p= new XML::Parser( Handlers => { Start => \&display_start_tag }, NoExpand => 1 ); $p->parse( \*DATA); sub display_start_tag { my( $p, $tag, %atts)= @_; # what XML::Parser gives you print "recognized: ", $p->recognized_string(), "\n\n"; print "tag: $tag\n"; foreach my $att (keys %atts) { print " $att: $atts{$att}\n"; } # what you can get ($tag, %atts)= parse_start_tag( $p->recognized_string()); print "\ntag: $tag\n"; foreach my $att (keys %atts) { print " $att: $atts{$att}\n"; } } sub parse_start_tag { my $string= shift; my( $gi, %atts); # get the gi (between < and the first space, / or > character) if( $string=~ s{^<\s*([^\s>/]*)[\s>/]*}{}s) { $gi= $1; } else { die "internal error when parsing start tag $string"; } while( $string=~ s{^([^\s=]*)\s*=\s*(["'])(.*?)\2\s*}{}s) { $atts{$1}= $3; } return $gi, %atts; } __DATA__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
regular expressions and newline characters
I have a file that looks like this joe bloggs herein lies the question posed by the user the question can be multi-lined like this one. == I'm trying to read the various tag content into variables: == sub ParseFile { my $file = 'submission6.xml'; #opened the file i want to parse open(FH, $file) || die "cannot open file: $!"; print "opening $file...\n\n"; #read contents into array my @stuff=; close(FH); #create one long string - why I'm not sure - but it worked with the regex below foreach my $stuff(@stuff) { $var=$var.$stuff; } my @details; # this grabs the text between and ($details[0])=$var=~/\(.*)\<\/FNAME\>/; # this grabs the text between and ($details[1])=$var=~/\(.*)\<\/SURNAME\>/; #I want this top grab all the text between and -newline characters included. ($details[2])=$var=~/\(.*)\<\/QDETAILS\>/;# #PROBLEM IS HERE==^^^ foreach $detail(@details) { print "$detail\n"; } } == the regex for FNAME and SURNAME work fine. But I can't grab the text between and because of newline characters I think. Any other tips on how to improve my code generally? Please help. Thanks, J _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XML::Parser -- Problem with undefined entities in element attributes
On Wednesday 15 August 2001 13:19, KAVANAGH, Michael wrote: > Interestingly, in testing this problem, I found that XML::Parser handles > ® in the attribute fine, but not, as I said, ®. The ascii value > entity seems to be handled ok. Can you confirm that in your experience this > is the case generally? I had never really tried this (I tend to avoid entities in attribute values as much as I can!) but it looks like you are right. The odd thing is that the recognized_string method returns the entity as is while the value passed to the Start handler converts it to a Unicode character. Go figure... -- Michel Rodriguez Perl & XML http://www.xmltwig.com Toulouse Perl Mongers: http://toulouse.pm.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regular expressions and newline characters
On Wednesday 15 August 2001 13:20, Joe Bellifont wrote: > I have a file that looks like this > > > joe > bloggs > herein lies the question posed by the user > the question can be multi-lined > like this one. > > > == > > I'm trying to read the various tag content into variables: > == > sub ParseFile { > my $file = 'submission6.xml'; > > > #opened the file i want to parse > open(FH, $file) || die "cannot open file: $!"; > print "opening $file...\n\n"; > #read contents into array > my @stuff=; > close(FH); > > > #create one long string - why I'm not sure - but it worked with the regex > below > foreach my $stuff(@stuff) { > $var=$var.$stuff; > } > > my @details; > # this grabs the text between and > ($details[0])=$var=~/\(.*)\<\/FNAME\>/; > > # this grabs the text between and > ($details[1])=$var=~/\(.*)\<\/SURNAME\>/; > > #I want this top grab all the text between and > -newline characters included. > ($details[2])=$var=~/\(.*)\<\/QDETAILS\>/;# > #PROBLEM IS HERE==^^^ > foreach $detail(@details) { > print "$detail\n"; > } > > } > > == > the regex for FNAME and SURNAME work fine. But I can't grab the text > between and because > of newline characters I think. > > Any other tips on how to improve my code generally? Hi, OK, so please bear with me, I am going to sound like an XML ayatollah ;--( First you really should not call, or even imply (the file name ending with .xml), that you are using XML when you are not: apart from instead of which is obviously a typo your document is _not_ well-formed XML: it misses a wrapping tag around the list of tags. Then if you want to process XML, you should never, _never_, _NEVER_! do it with regular expressions (OK, maybe there are cases where you can use regexps, but they involve huge amounts of data, throw-away conversions and generally knowing exactly what you are doing and why). Use the parser luke! There are just too many potential traps for you to write a robust XML::Parser with regexps. Especially as there is an existing parser, plus a host of XML modules that will make your life much easier. In fact if you can install XML::Parser and XML::Simple on your system it will be dead easy for you to get the values of the fields in a hash: #!/bin/perl -w use strict; use XML::Simple;# depends on XML::Parser use Data::Denter;# just to check what's read in by XML::Simple my $data= XMLin( \*DATA); # read the data, you would use "./$file" print Denter( $data), "\n"; # just checking # yes, it's that simple! foreach my $field qw( FNAME SURNAME QDETAILS) { print "$field: $data->{$field}\n"; } __DATA__ joe bloggs herein lies the question posed by the user the question can be multi-lined like this one. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: index inside foreach{ ..}
I don't know if you can do it using a foreach but I would use a for loop. It may be just a tad slower but you'll get the results you're looking for. Using the loop below will start at the last index of the array @a and loop down to the first (assuming that the first index of the array is 0). @a = ("a","b","c","d","e"); for ($b=$#a; $b > -1; $b--) { print "$b $a[$b]\n"; }; In the loop you showed using the $index counter, the $index would not be the actual index of the item in the array but the current index of the loop. Maybe one of the more experienced people on the list can offer you a way of doing it using a foreach loop that might be faster. Hope this helps, Chris -Original Message- From: matthschulz [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 14, 2001 6:40 PM To: [EMAIL PROTECTED] Subject: index inside foreach{ ..} I have read something but could not find an answer: I had to do a foreach like this: A @a = ("a","b","c","d","e"); foreach $b (reverse @a) { print "$b\n"; }; Now i needed to access the index inside the foreach to do: B @a = ("a","b","c","d","e"); foreach $b (reverse @a) { print "$index $b\n"; }; which i did with a additional variable C @a = ("a","b","c","d","e"); $index =0; foreach $b (reverse @a) { $index++; print "$index $b\n"; }; Is there a way to acces the internal index of the foreach loop as $index in example "B" ? Thanks in advance Matth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Module Administration question
Greetings all, I am the perl administrator here, and new to both perl as a programming language, and as the site admin. I've got no problem getting modules. My question is how do I remove them? In particular, I'm in a Solaris site, and had to install the DBD bundle and Sybase DBI. I ended up with a module useful mostly for win32, named DBD::ADO. Just removing it from the tree seemed to be insufficient. There doesn't seem to be any way to remove it via the CPAN interactive shell. Any suggestions will be gratefully appreciated. Thanks for the help. Regards, Steve Starer Senior Systems Engineer Fahnestock & Company (212) 668-1281 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
how do I know what modules are installed
I have to install the xml parser module. I have root access. How do I know if it is already installed and how can I get a list of all installed modules thanks. -J _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how many items in a hash?
--- Piers Cawley <[EMAIL PROTECTED]> wrote: > Note that the number of used buckets isn't (necessarily) the same as > the number of items in the hash. Can you give an example of how they could be different? __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do I know what modules are installed
On Wednesday 15 August 2001 14:29, Joe Bellifont wrote: > I have to install the xml parser module. > I have root access. > > How do I know if it is already installed and > how can I get a list of all installed modules If you try to use it and you can't then it is not installed ;--) Or just try perldoc XML::Parser and see if you get something. If you are on Windows and use Activestate Perl then it will be already installed, as it is used in PPM Note that before installing XML::Parser you will need to install the expat library that you can get at http://sourceforge.net/projects/expat/ -- Michel Rodriguez Perl & XML http://www.xmltwig.com Toulouse Perl Mongers: http://toulouse.pm.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Problem running script on WinNT4 machines. - Win32::Netadmin
Hi all, Hopefully someone could help me with a small problem that im having, part of one of my scripts uses functions from Win32::NetAdmin and it works fine when running from a windows 2000 pc but not an NT4 pc. Basically the script takes the name of a pc as input, lists the members of the local administrator group and then gives the user some options such as removing users, adding users, or setting the group back so that it only contains our companies default setting for local admin groups. The script runs ok on a NT4 machine, but when it comes to the subroutine for retreiving and printing the local admin group members, nothing is output to the screen. It the OS of the target PC does not make any difference. Running on a w2k works perfectly, and never works on NT4. A sample subroutine is below, I can't see much wrong with it. I'm wondering if there is a problem using the NetAdmin module on NT4 machines ?? Any help would be greatly appreciated. Many thanks. Adrian. - sub showMembers { $console->Write("\n\n $pcName`s local administrator group contains: \n\n"); Win32::NetAdmin::LocalGroupGetMembersWithDomain("$pcName", "Administrators", \@users); for (my $i=0; $i<@users; $i++){ $console->Write(" $users[$i]\n"); } $console->Write("\n\n"); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
status messages as the program progresses
Hello everyone, I have a while loop that loops through a text file for quite a while (10 min or so). Is there any way to print a status-type message while it's looping through? I did something like this now: my $i=0; while ($i le "1000") { print "Processing\r"; } And that works, but if I run the script like this: ./script.pl > test.txt I get a BUNCH of "Processing" lines in test.txt. Is there any other way I can do this? Thanks, Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Module Administration question
On Wed, Aug 15, 2001 at 08:07:25AM -0400, Steve Starer wrote: > I am the perl administrator here, and new to both perl as a programming > language, and as the site admin. I've got no problem getting modules. My > question is how do I remove them? In particular, I'm in a Solaris site, and > had to install the DBD bundle and Sybase DBI. I ended up with a module > useful mostly for win32, named DBD::ADO. DBD::ADO installs with DBI (this may change soon), as does a number of other pure perl drivers. > Just removing it from the tree seemed to be insufficient. There doesn't seem > to be any way to remove it via the CPAN interactive shell. Any suggestions > will be gratefully appreciated. Currently if you want to remove it using CPAN, you'll need to remove DBI ... not a good solution. If your reason is because CPAN reports a version difference, you can either use CPAN to force install DBD::ADO, hack the version number in DBD::ADO, or ignore it. Tim Bunce is (DBI author) is considering removing the pure perl drivers for DBI in favor of using Bundle::DBI. On the other had, you can review and send patches to help improve DBD::ADO, it is pure (some places ugly) perl code ... ;-> Tom _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Tk::FileDialog -FPat question
Is there a way to show upper and lower case pattern match for the -FPat option for a dialog box default pattern: sub browse_files { my $save_name = $b_file; $status->configure(-text=>"Browse directories"); if ($base ) { $b_file = $file_dialog->Show( -Path => $base, -FPat => "*$mnem*"); $b_file = $save_name if !$b_file; } return $b_file; } $mnem is in upper case as in MNEM and I would like to display all files that have '*MNEM*' or '*mnem*' in the filename. I've read the perldoc's for FileDialog and I couldn't find anything in there. Thanks, Tom -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do I know what modules are installed
running `perl -e 'use XML:Parser'` should do the trick. If you get the prompt back, it's installed. Otherwise, you get the "Can't locate..." message. --sal --- Michel Rodriguez <[EMAIL PROTECTED]> wrote: > On Wednesday 15 August 2001 14:29, Joe Bellifont > wrote: > > I have to install the xml parser module. > > I have root access. > > > > How do I know if it is already installed and > > how can I get a list of all installed modules > > If you try to use it and you can't then it is not > installed ;--) Or just try > perldoc XML::Parser and see if you get something. If > you are on Windows and > use Activestate Perl then it will be already > installed, as it is used in PPM > > Note that before installing XML::Parser you will > need to install the expat > library that you can get at > http://sourceforge.net/projects/expat/ > -- > Michel Rodriguez > Perl & XML > http://www.xmltwig.com > Toulouse Perl Mongers: http://toulouse.pm.org > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Module Administration question
Thanks for the quick reply! I think my greater question is how to remove/uninstall any module. This all got started when I began working through the Perl DBI book. The very first example program bombed when it hit the ADO module. The module is missing something it needs - Win32/OLE/Variant.pm. I can't think of a reason I'd want to install this on a Solaris machine anyway, so for now all I want to do is rid myself of ADO. On the other had, you can review and send patches to help improve DBD::ADO, it is pure (some places ugly) perl code ... ;-> LOL on that one. I don't consider my perl skills strong enough to be a contributor yet. Then again, everybody learns to walk the same way... Thanks again, and perhaps you can follow up with some tips on getting rid of unwanted Perl mods. Regards, Steve Starer -Original Message- From: Thomas A. Lowery [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 10:12 AM To: Steve Starer Cc: [EMAIL PROTECTED] Subject:Re: Module Administration question On Wed, Aug 15, 2001 at 08:07:25AM -0400, Steve Starer wrote: > I am the perl administrator here, and new to both perl as a programming > language, and as the site admin. I've got no problem getting modules. My > question is how do I remove them? In particular, I'm in a Solaris site, and > had to install the DBD bundle and Sybase DBI. I ended up with a module > useful mostly for win32, named DBD::ADO. DBD::ADO installs with DBI (this may change soon), as does a number of other pure perl drivers. > Just removing it from the tree seemed to be insufficient. There doesn't seem > to be any way to remove it via the CPAN interactive shell. Any suggestions > will be gratefully appreciated. Currently if you want to remove it using CPAN, you'll need to remove DBI ... not a good solution. If your reason is because CPAN reports a version difference, you can either use CPAN to force install DBD::ADO, hack the version number in DBD::ADO, or ignore it. Tim Bunce is (DBI author) is considering removing the pure perl drivers for DBI in favor of using Bundle::DBI. On the other had, you can review and send patches to help improve DBD::ADO, it is pure (some places ugly) perl code ... ;-> Tom _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: how many items in a hash?
I am using a hash to iterate over and when I get a hit, I delete the key: HashStart: 148/256 #<- start of processing Pass 1 130 74/256 Pass 2 41 39/256 Pass 3 23 17/256 Pass 4 11 7/256 Pass 5 7 0 # hash is cleared I don't believe you as an individual have any control over what is allocated. This is handled by Perl. Wags ;) -Original Message- From: John Sands [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 05:30 To: Piers Cawley Cc: '[EMAIL PROTECTED]' Subject: Re: how many items in a hash? --- Piers Cawley <[EMAIL PROTECTED]> wrote: > Note that the number of used buckets isn't (necessarily) the same as > the number of items in the hash. Can you give an example of how they could be different? __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: status messages as the program progresses
> -Original Message- > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, August 15, 2001 10:13 AM > To: Perl-Beginners > Subject: status messages as the program progresses > > > Hello everyone, > > I have a while loop that loops through a text file for quite > a while (10 > min or so). Is there any way to print a status-type message > while it's > looping through? > I did something like this now: > > my $i=0; > while ($i le "1000") { > print "Processing\r"; > } I hope that's not the whole script, since $i doesn't change :) > > And that works, but if I run the script like this: > ./script.pl > test.txt > > I get a BUNCH of "Processing" lines in test.txt. Is there > any other way I > can do this? One thing you can do is print the message every so many lines. my $i = 0; while (<>) { # (...process line here...) print "$i lines processed\n" unless ++$i % 100; } This will print: 100 lines processed 200 lines processed 300 lines processed and so on. Or, you can print the message every so many seconds: my $last_time = time; my $i = 0; while (<>) { # (...process line here...) $i++; print("$i lines processed\n"), $last_time = time if time - $last_time > 30; } This uses the variable $last_time to keep track of when a message was last printed. If this has been more than 30 seconds, a line is printed and the $last_time variable is updated. These methods assume each iteration of the loop is relatively quick. If the processing for a single line can be lengthy, you can use a $SIG{ALRM} handler to cause an interrupt in the middle of processing. However, it's generally not a good idea to do I/O during an event handler, so you usually set a flag that you check somewhere inside your processing loop. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: status messages as the program progresses
:) forgot to add the $i++. And that was just an example. On Wed, 15 Aug 2001 10:55:58 -0400 Bob Showalter <[EMAIL PROTECTED]> wrote: > > -Original Message- > > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > > Sent: Wednesday, August 15, 2001 10:13 AM > > To: Perl-Beginners > > Subject: status messages as the program progresses > > > > > > Hello everyone, > > > > I have a while loop that loops through a text file for quite > > a while (10 > > min or so). Is there any way to print a status-type message > > while it's > > looping through? > > I did something like this now: > > > > my $i=0; > > while ($i le "1000") { > > print "Processing\r"; > > } > > I hope that's not the whole script, since $i doesn't change :) > > > > > And that works, but if I run the script like this: > > ./script.pl > test.txt > > > > I get a BUNCH of "Processing" lines in test.txt. Is there > > any other way I > > can do this? > > One thing you can do is print the message every so many lines. > >my $i = 0; >while (<>) >{ ># (...process line here...) >print "$i lines processed\n" unless ++$i % 100; >} > > This will print: > >100 lines processed >200 lines processed >300 lines processed > > and so on. > > Or, you can print the message every so many seconds: > >my $last_time = time; >my $i = 0; >while (<>) >{ ># (...process line here...) >$i++; >print("$i lines processed\n"), $last_time = time if time - > $last_time > > 30; >} > > This uses the variable $last_time to keep track of when a message was > last > printed. If this has been more than 30 seconds, a line is printed and > the > $last_time variable is updated. > > These methods assume each iteration of the loop is relatively quick. If > the > processing for a single line can be lengthy, you can use a $SIG{ALRM} > handler > to cause an interrupt in the middle of processing. However, it's > generally > not a good idea to do I/O during an event handler, so you usually set a > flag > that you check somewhere inside your processing loop. > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XML::Parser -- Problem with undefined entities in element attributes
- Original Message - From: KAVANAGH, Michael <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 12:28 PM Subject: XML::Parser -- Problem with undefined entities in element attributes > Hi there, > I've been bumping my head up against this problem all morning now, and can't > come up with an answer, maybe someone with XML::Parser experience can help. > The XML::Parser documentation doesn't really have any suggestions. > > Normally you can use the NoExpand method to prevent the parser from > expanding entity references in the text. > But this doesn't affect entity references that appear in attribute values. > > Is there any way to handle entity references in attribute values? Actually more then one way. Depends if you want to preserve the entities or translate them... > My problem is I have tags in my xml that contain entity references like > this: > > > and XML::Parser generates the following error: > undefined entity at line 6, column 33, byte 218: > > > ===^ All non-standard entities (and there are quit some) should be in the DOCTYPE declaration at the top of the document. SO there should be something there like: ] > > So obviously ® isn't in the internal set of references, and it is > generating an error. > I'd like to set up a handler for this condition, rather than having the > program die! If you want to preserve the entities you could translate them to some other string and then put them back in a starttag handler. You have to construcy the start tag there (modifying the %attrs hash wont change the attributes in the original element). > I have tried setting the ExternEnt handler to handle this case, but it > doesn't seem to get triggered in this instance. Nope ExternEnt is fired when the parser sees an external entity reference (or was it a declaration)... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl scripts
On Wed, Aug 15, 2001 at 12:14:25PM +0200, Jos I. Boumans wrote: > it's in the last line: > kill 'HUP',`cat $PIDFILE`; > > it's a unix command to kill *nix processes... which of course won't work on > windows... kill does work on Windows, and in 5.6.1 (possibly 5.6.0 too) even works on arbitrary process numbers. See perldoc perlport. Though it very well could be that kill on Windows doesn't understand 'HUP', and would prefer a number, rather than a name. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl scripts
i was referring to the entire line (ie, the command). and i stand by my former reply: try the win32::* modules for interaction with windows first, before reinventing the wheel. Jos - Original Message - From: "Michael Fowler" <[EMAIL PROTECTED]> To: "Jos I. Boumans" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 7:05 PM Subject: Re: perl scripts > On Wed, Aug 15, 2001 at 12:14:25PM +0200, Jos I. Boumans wrote: > > it's in the last line: > > kill 'HUP',`cat $PIDFILE`; > > > > it's a unix command to kill *nix processes... which of course won't work on > > windows... > > kill does work on Windows, and in 5.6.1 (possibly 5.6.0 too) even works on > arbitrary process numbers. See perldoc perlport. > > Though it very well could be that kill on Windows doesn't understand 'HUP', > and would prefer a number, rather than a name. > > > Michael > -- > Administrator www.shoebox.net > Programmer, System Administrator www.gallanttech.com > -- > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
System command via CGI not working....but should
Hello, I am trying to get a CGI script to run a system command.for example system `/usr/sbin/adduser larry' or die "User was not added" $?; I have this line in a script and have set Apache to be run as root (don't worry, all this is being done on a test box...I know the security risks) and I get an error from adduser that it cannot lock the password file. Very strange because.on another box I have the same code working! The code that is working is below... First index.cgi is called --INDEX.CGI-- #!/usr/bin/perl push (@INC, "/usr/local/interface/server"); require 'cgi-lib.pl'; require 'stub.pl'; exit; --END INDEX.CGI- Very straight forward so far.all the action takes place in stub.pl. -STUB.PL- # Input Variables: # # "zone" -- the zone we're working with. # "query" -- the kind of query we're making. # "recordnum" -- the line number of the record to manipulate # "confirmed" -- confirmed a request we sent # "host" -- The hostname or IP address to work with # "record" -- The type of record to work with # "data" -- Any extra arguments # Included Functions: # # "findroot" -- Find the root named directory. # From: common.pl # "findzone" -- Find the zone file of a specified zone # From: common.pl # "getlocalip" -- Gets the local IP address. # From: common.pl # "getlocalhost" -- Gets the local host. # From: common.pl # "excludeblock" -- Excludes a block of text. # From: blockmanip.pl # Unique Functions # "printzone" -- print out a zone # Uses: &findzone # Output: Prints out the requested zone. # Returns: Nothing. # "delrecord" -- print out a zone, except a specified line # Uses: &findzone, $recordnum # Output: Zone file, minus the specified line. # Returns: Nothing. # "finddomains" -- Find the domains hosted on the machine # Uses: $zone # Output: Domains hosted according to /etc/named.conf. # Returns: Nothing. # "delzone" -- Searches /etc/named.conf, and removes a zone from it # Uses: $zone # Output: Prints out the zone, minute the specified line. # Returns: Nothing. # "addzone" -- Attempts to add a zone. # Uses: &findzone # "addrecord" -- Attempts to add a record to a zone. # "gettimargs" -- Attempts to find the time configuration # Uses: &findzone # Returns: Array of time arguments # "incserial" -- Increments the serial number # Uses: &gettimeargs # Returns: Current serial number + 1, or error code @NEWINC = ( "/usr/local/interface/server/include", "/usr/local/interface/server/templates", "/usr/local/interface/server/functions", ); push(@INC, @NEWINC); undef @NEWINC; &ReadParse(*input); if ((getpwuid($<))[0] ne 'nobody' || ( (getgrgid($())[0] ne 'shadow' && (getgrgid($())[0] ne 'nobody' ) ) { die "I will not function except as child of Apache!\n"; } unless ($ENV{'REMOTE_USER'} && $ENV{'SERVER_NAME'}) { die "I will not function outside of a cgi context!\n"; } require 'config.pl'; require 'getdtpwnam.pl'; sub comment { # insert hidden snide comments for debugging if ($debug) { print "\n"; } } # Begin main code. # Redirect STDERR to STDOUT. open(STDERR,">&STDOUT"); select STDERR; $| = $1; # Stard printing out. print "Content-type: text/html\r\n\r\n", ''; #print "Content-type: text/plain\r\n\r\n"; # Call the queried function. $< = 0; $> = 0; unless ($ENV{'REMOTE_USER'} && $ENV{'SERVER_NAME'}) { die "I will not function outside of a cgi context!\n"; } unless ( ( getdtpwnam($ENV{'REMOTE_USER'}))[1] eq $ENV{'SERVER_NAME'} ) { &comment("User \($ENV{'REMOTE_USER'}\) and Server Name \($ENV{'SERVER_NAME'}\) denied!.\n"); print "Error! Incorrect domain name attachment!\n"; die "\tCannot verify secure user; dying...\n"; } else { &comment("User \($ENV{'REMOTE_USER'}\) and Server Name \($ENV{'SERVER_NAME'}\) accepted.\n"); } umask 022; if ($input{'query'} =~ /(\S+)/) { $query = $1; } unless ($query) { die "No query specified, giving up...\n"; } require "${query}.pl"; &$query; 1; END STUB.PL Basically what happens is this script receives input from a form (ReadParse section) and then makes sure that it is a child of Apache and I believe the lines that do: $< = 0; $> = 0; change the ownership of the process to the root user and group(BTW on my system root is 0 in both /etc/passwd and /etc/group). I THINK that is what this does, but PLEASE correct me if I'm wrong. That being said, the process (that is, everything the script is doing from this point) *should* be operating as the root user, correct? Then the line: umask 022; if I understand correctly, makes sure that everything created by the process from this point on has the permissions 755. (correct me if I'm wro
URL access
Hello. Im looking for a little direction: I want to write a very simple script that goes out to a particular set of web sites (weather maps) and prints/saves their contents. Ive been reading about sockets and networking but I havent been able to glean the information that I think I need. Does anyone have a hint? Im interested in doing this either from a UNIX box or NT. Thanks very much. -Tyler Cruickshank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: URL access
This is exactly what LWP is for... it comes standard with activestate's distro of perl (www.activestate.com) but not with *nix iirc. you can grab the module from cpan and just read up on the docs of LWP::Simple it does all you need =) hth Jos - Original Message - From: "Tyler Cruickshank" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 9:44 PM Subject: URL access Hello. Im looking for a little direction: I want to write a very simple script that goes out to a particular set of web sites (weather maps) and prints/saves their contents. Ive been reading about sockets and networking but I havent been able to glean the information that I think I need. Does anyone have a hint? Im interested in doing this either from a UNIX box or NT. Thanks very much. -Tyler Cruickshank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: URL access
Apologize for the naivety, but there are so many modules related with LWP at cpan ( I searched for LWP), which one do I download? And how do I know if we already have LWP module at our local machine? thank you very much!! -Jennifer Pan -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 3:49 PM To: Tyler Cruickshank; [EMAIL PROTECTED] Subject: Re: URL access This is exactly what LWP is for... it comes standard with activestate's distro of perl (www.activestate.com) but not with *nix iirc. you can grab the module from cpan and just read up on the docs of LWP::Simple it does all you need =) hth Jos - Original Message - From: "Tyler Cruickshank" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 9:44 PM Subject: URL access Hello. Im looking for a little direction: I want to write a very simple script that goes out to a particular set of web sites (weather maps) and prints/saves their contents. Ive been reading about sockets and networking but I havent been able to glean the information that I think I need. Does anyone have a hint? Im interested in doing this either from a UNIX box or NT. Thanks very much. -Tyler Cruickshank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: URL access
to be on the safe side, just get bundle::lwp it has all you'll ever need probably! - Original Message - From: "Jennifer Pan" <[EMAIL PROTECTED]> To: "Jos I. Boumans" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 9:51 PM Subject: RE: URL access Apologize for the naivety, but there are so many modules related with LWP at cpan ( I searched for LWP), which one do I download? And how do I know if we already have LWP module at our local machine? thank you very much!! -Jennifer Pan -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 3:49 PM To: Tyler Cruickshank; [EMAIL PROTECTED] Subject: Re: URL access This is exactly what LWP is for... it comes standard with activestate's distro of perl (www.activestate.com) but not with *nix iirc. you can grab the module from cpan and just read up on the docs of LWP::Simple it does all you need =) hth Jos - Original Message - From: "Tyler Cruickshank" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 15, 2001 9:44 PM Subject: URL access Hello. Im looking for a little direction: I want to write a very simple script that goes out to a particular set of web sites (weather maps) and prints/saves their contents. Ive been reading about sockets and networking but I havent been able to glean the information that I think I need. Does anyone have a hint? Im interested in doing this either from a UNIX box or NT. Thanks very much. -Tyler Cruickshank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: URL access
> -Original Message- > From: Jennifer Pan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, August 15, 2001 3:51 PM > To: Jos I. Boumans > Cc: [EMAIL PROTECTED] > Subject: RE: URL access > > > Apologize for the naivety, but > there are so many modules related with LWP at cpan ( I searched for > LWP), which one do I download? > And how do I know if we already have LWP module at our local machine? After you install Bundle::LWP to grab everything, use the command perldoc LWP for top-level documentation. There are numerous classes, but the "biggies" are probably: LWP::Simple LWP::UserAgent HTTP::Request HTTP::Response URI -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perlembed in Perl 5.6.1?
Anybody attempt to embed Perl in C with Perl 5.6.1. It works fine in Perl 5.0053. But in the newer version, it says that Dynamic loading is not available in this perl. I already compiling perl with -Dusedl and such, but to no avail. - philipd -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
GetOpt::Long - Usage question
Hi, I am unable to get the following inherited code, using Getopt::Long, to work. It is my understanding that Perl will automatically create a $opt_help variable ( for a -help command line option). However, when I try to print it's value, it returns a null value. In addition, the "help" mesage is never printed. Here is the output of the program, when I run it: %perl gtopt.pl -help The value of $opt_help is : Any help and pointers on what might be wrong would be greatly appreciated. Thanks PN -- Source Code -- #/usr/bin/perl -w use strict; # Forward declarations my $opt_help; sub GetCmdLine; # Begin of Main Body &GetCmdLine(); # End of Main Body ## Sub GetCmdLine ## sub GetCmdLine { use Getopt::Long; $Getopt::Long::ignorecase; $Getopt::Long::autoabbrev; &GetOptions("help|h"); # Print the value of $opt_help print "The value of \$opt_help is : ", $opt_help, "\n"; if (defined($opt_help) && ($opt_help ==1)) { print "\n\nUsage: $0 [options] \n"; print " [optins]:\n"; print "\t\t-h Prints this help message header.\n"; } } __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: GetOpt::Long - Usage question
On Wed, Aug 15, 2001 at 02:49:34PM -0700, pn wrote: > #/usr/bin/perl -w > use strict; > > # Forward declarations > > my $opt_help; This is your problem right here. Getopt::Long sets the package global $main::opt_help, but now that you've declared the variable lexical, anytime you access it unqualifed in your program you'll get the lexical variable. The solution is to either declare it global, with our or use vars, or pass in a variable to GetOptions. E.g. our $opt_help; GetOptions('help|h'); OR use vars qw($opt_help); GetOptions('help|h'); OR GetOptions('help|h' => \$opt_help); OR (my preference) GetOptions(\%opts, 'help|h'); # now available as $opts{'help'} Some further commentary is below. > sub GetCmdLine; > > # Begin of Main Body > > &GetCmdLine(); > > # End of Main Body > > ## > Sub GetCmdLine > ## > > sub GetCmdLine { > > use Getopt::Long; It's generally better to place use lines near the beginning of the file; that's, conceptually, when they get executed, regardless of their position in the code, and it provides an easy way for someone to determine the dependencies your code has. > $Getopt::Long::ignorecase; > $Getopt::Long::autoabbrev; I don't know what you intend to accomplish with these. You're simply mentioning the variables, you aren't assigning any values to them. > > &GetOptions("help|h"); > > # Print the value of $opt_help >print "The value of \$opt_help is : ", > $opt_help, "\n"; > > if (defined($opt_help) && ($opt_help ==1)) { It's easier to test simply for truth: if ($opt_help) { > print "\n\nUsage: $0 [options] \n"; > print " [optins]:\n"; > print "\t\t-h Prints this help message > header.\n"; > > } > } Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
binary files
Hello. Im still struggling with converting a binary file to an ascii file. I just dont understand how to use seek and unpack. I understand that one needs to know the format of the binary file, therefore, I have pasted below FORTRAN code that reads the ascii file and writes a binary file. The files I work with are typically meteorological files full of numbers (and short headers) that need to be averaged or interpolated etc.. I just need to do it in perl. In FORTRAN, the ascii file is simply read (with a known format ie. 2100) and written to an unformatted binary file. In this example, the code "knows" the format (or the elements of each record) of the ascii file. My goal is to be able to: 1) convert a binary file to ascii and 2) to read and manipulate (or use) a binary file on the fly (w/o using the FORTAN code). If anyone else could provide further direction it would be very appreciated. Thanks, - Tyler Cruickshank FORTRAN CODE: #- OPEN (5,FILE=File.ascii) OPEN (9,FORM='UNFORMATTED',FILE=File.binary) READ(5,2100)IFILE, NOTE,NSEG, NSPECS, IDATE, BEGTIM, JDATE, ENDTIM WRITE(9)IFILE,NOTE,NSEG,NSPECS,IDATE,BEGTIM,JDATE,ENDTIM READ(5,2001) ORGX, ORGY, IZONE, UTMX, UTMY, DELTAX, DELTAY, NX, NY, NZ, NZLOWR, NZUPPR, HTSUR, HTLOW, HTUPP WRITE(9) ORGX,ORGY,IZONE,UTMX,UTMY,DELTAX,DELTAY,NX,NY, NZ,NZLOWR,NZUPPR,HTSUR,HTLOW,HTUPP READ(5,1002) IX, IY, NXCLL, NYCLL WRITE(9)IX,IY,NXCLL,NYCLL READ(5,1003) ((MSPEC(M,L),M=1,10),L=1,NSPECS) 10 IBHR=BEGTIM + 1 IEHR=ENDTIM WRITE (9)((MSPEC(I,J),I=1,10),J=1,NSPECS) 2100 FORMAT(10A1,60A1,/,I2,1X,I2,1X,I6,F6.0,I6,F6.0) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
wheelmouse
hello dont know if its the right place to ask such a question please pardon me im actually practicing perl/tk how can i make my wheel mouse to works with scrollable text/entry ... widgets ?? any help will be greatly appreciated tom -- si quelqun peut me dire comment avoir son propre groupe de discussion ça serais supers simpas je vous remercis d'avance -+-E... in : GNU - Je suis un groupe de news à moi tout seul -+- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
s/^W+//;
Hi I'm reading data from MSAccess, joining 2 fetched values with a comma and writing to another table. The data seems to be padded. My resultant column shows some space between the two values eg valuefromFirstcolumn, valuefromSecondcolumn I have tried applying a regex $valuefromFirstcolumn =~s/W+$//; & $valuefromFirstcolumn =~s/s+$//; with no success. Assistance appreciated. Regards CCJ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: binary files
At 04:58 PM 8/15/01 -0600, Tyler Cruickshank wrote: >Hello. Im still struggling with converting a binary file to an ascii >file. I just dont understand how to use seek and unpack. I understand >that one needs to know the format of the binary file, therefore, I have >pasted below FORTRAN code that reads the ascii file and writes a binary >file. The files I work with are typically meteorological files full of >numbers (and short headers) that need to be averaged or interpolated etc.. >I just need to do it in perl. In FORTRAN, the ascii file is simply read >(with a known format ie. 2100) and written to an unformatted binary >file. In this example, the code "knows" the format (or the elements of >each record) of the ascii file. > >My goal is to be able to: > >1) convert a binary file to ascii and >2) to read and manipulate (or use) a binary file on the fly (w/o using the >FORTAN code). > >If anyone else could provide further direction it would be very appreciated. > >Thanks, - Tyler Cruickshank > >FORTRAN CODE: >#- >OPEN (5,FILE=File.ascii) >OPEN (9,FORM='UNFORMATTED',FILE=File.binary) > >READ(5,2100)IFILE, NOTE,NSEG, NSPECS, IDATE, BEGTIM, JDATE, ENDTIM >WRITE(9)IFILE,NOTE,NSEG,NSPECS,IDATE,BEGTIM,JDATE,ENDTIM > >READ(5,2001) ORGX, ORGY, IZONE, UTMX, UTMY, DELTAX, DELTAY, NX, NY, NZ, >NZLOWR, NZUPPR, HTSUR, HTLOW, HTUPP >WRITE(9) ORGX,ORGY,IZONE,UTMX,UTMY,DELTAX,DELTAY,NX,NY, >NZ,NZLOWR,NZUPPR,HTSUR,HTLOW,HTUPP > >READ(5,1002) IX, IY, NXCLL, NYCLL >WRITE(9)IX,IY,NXCLL,NYCLL > >READ(5,1003) ((MSPEC(M,L),M=1,10),L=1,NSPECS) >10 IBHR=BEGTIM + 1 >IEHR=ENDTIM >WRITE (9)((MSPEC(I,J),I=1,10),J=1,NSPECS) > > >2100 FORMAT(10A1,60A1,/,I2,1X,I2,1X,I6,F6.0,I6,F6.0) I can't resist a program with the variable name 'ORGY' :-) I know less about unpack() than I would like. Therefore I would be willing to debug this one with you if you can point me to a sample binary file and expected results. On the face of it, I would say that these unpack templates would be heading in the right direction: I5dId I3d4I5d3 I4 But you don't show your variable declarations and I can't remember whether 'H' is implicit integer. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: s/^W+//;
On 8/15/01 4:28 PM, Clinton wrote: > Hi > I'm reading data from MSAccess, joining 2 fetched values with a comma and > writing to another table. The data seems to be padded. My resultant column > shows some space between the two values eg > valuefromFirstcolumn, valuefromSecondcolumn > > I have tried applying a regex > $valuefromFirstcolumn =~s/W+$//; > & > $valuefromFirstcolumn =~s/s+$//; > with no success. > Assistance appreciated. > Regards > CCJ > Erm, you want to remove W's and S's at the end of $valuefromFirstcolumn? If you're trying to remove all non-word characters, you'd say: $valuefromFirstcolumn =~s/\W+//g; But I don't think that's what you want, as you'd end up with valuefromFirstcolumnvaluefromSecondcolumn from your example. I'm not sure quite what you want, but you might want to try $valuefromFirstcolumn =~s/\s+//g; which should be self explanatory. I recommend buying and reading the camel book ("Programming Perl, 3rd ed.", by Larry Wall, Tom Christiansen, and Jon Orwat). It has a nice big chapter on regexes. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: s/^W+//;
Thank you Michael. I missed the "\".Works fine now. - Original Message - From: "Michael Kelly" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, August 16, 2001 9:43 AM Subject: Re: s/^W+//; > On 8/15/01 4:28 PM, Clinton wrote: > > > Hi > > I'm reading data from MSAccess, joining 2 fetched values with a comma and > > writing to another table. The data seems to be padded. My resultant column > > shows some space between the two values eg > > valuefromFirstcolumn, valuefromSecondcolumn > > > > I have tried applying a regex > > $valuefromFirstcolumn =~s/W+$//; > > & > > $valuefromFirstcolumn =~s/s+$//; > > with no success. > > Assistance appreciated. > > Regards > > CCJ > > > > Erm, you want to remove W's and S's at the end of $valuefromFirstcolumn? If > you're trying to remove all non-word characters, you'd say: > > $valuefromFirstcolumn =~s/\W+//g; > > But I don't think that's what you want, as you'd end up with > > valuefromFirstcolumnvaluefromSecondcolumn > > from your example. I'm not sure quite what you want, but you might want to > try > > $valuefromFirstcolumn =~s/\s+//g; > > which should be self explanatory. > > I recommend buying and reading the camel book ("Programming Perl, 3rd ed.", > by Larry Wall, Tom Christiansen, and Jon Orwat). It has a nice big chapter > on regexes. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
constructor modification/inheritance
Hi *, I am rather a beginner to Perl (and programming) but am nevertheless faced with maintaining a complex OO environment. Yikes! Anyway, here is my problem: I have two classes whose constructors return a db handle. "A" accepts parameters for user/password, while "B", although it uses A to connect as well, does not acccept any parameters, thus connecting only as root. All the keen methods belong to the latter class, and since I want to connect via CGI and display the information they provide to the masses via their browser, without them entering passwords, I need to know how to use A's ability to connect with B's great methods. I've heard of something called overloading, but can this apply to constructors? Or do I need a whole new class, copying and pasting the stuff I need, cmopletely undermining the OO philosophy? I know better than to mess with the "black box". Here are the classes: A sub new { my $proto=shift; my $specs=shift; my $class=ref($proto) || $proto; my $self={}; $self->{connection}= X::connect($specs); return undef unless defined $self->{$connection}; bless ($self,$class); return $self; B sub new { my $proto=shift; my $specs=shift; my $class=ref($proto) || $proto; my $self={}; $self->{X} = X->new(); $self->{connection}= $self->{X}->{connection}; return undef unless defined $self->{$connection}; bless ($self,$class); return $self; Many many thanks for this wonderful mailing list. Cheers, Blair __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Module Administration question
Steve Starer [[EMAIL PROTECTED]] quoth: *>Thanks for the quick reply! I think my greater question is how to *>remove/uninstall any module. This all got started when I began working *>through the Perl DBI book. The very first example program bombed when it hit Nope, there isn't any function that I'm aware of in either CPAN.pm or the Perl core that will remove modules for you. However, there is a module in the core called ExtUtils::Installed that, with a little toying with, you can write a script that will inventory all the files associated with a module whereupon you can delete them. Also remember that you'll need to remove the entry in perllocal.pod. You could also get the pmtools suite and modify what you need a wee bit or use the tools in a quickie script. http://language.perl.com/misc/pmtools-1.00.tar.gz. Maybe there needs to be a pmdel in that suite. hmm. enjoy. e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do I know what modules are installed
Joe Bellifont [[EMAIL PROTECTED]] quoth: *> *>How do I know if it is already installed and *>how can I get a list of all installed modules http://www.cpan.org/misc/cpan-faq.html#How_installed_modules e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constructor modification/inheritance
At 05:36 AM 8/15/01 -0700, Blair Burns wrote: >Hi *, > >I am rather a beginner to Perl (and programming) but >am nevertheless faced with maintaining a complex OO >environment. Yikes! Anyway, here is my problem: I have >two classes whose constructors return a db handle. "A" >accepts parameters for user/password, while "B", >although it uses A to connect as well, does not >acccept any parameters, thus connecting only as root. The B in your code uses an X to connect, not A. Perhaps you're eliding too much information. >All the keen methods belong to the latter class, and >since I want to connect via CGI and display the >information they provide to the masses via their >browser, without them entering passwords, I need to >know how to use A's ability to connect with B's great >methods. I've heard of something called overloading, >but can this apply to constructors? There's no function overloading in the C++ sense (not without using some modules I'm not prepared to get into). There is operator overloading, but a constructor is not an operator. >Or do I need a >whole new class, copying and pasting the stuff I need, >cmopletely undermining the OO philosophy? I know >better than to mess with the "black box". Sometimes the black box needs messing with. Without seeing more code it's hard to tell, but perhaps you could get what you want without modifying existing modules by subclassing B and overriding its constructor. Cut and paste the existing constructor and modify it to pass parameters. >Here are the >classes: > >A >sub new { > my $proto=shift; > my $specs=shift; > my $class=ref($proto) || $proto; > my $self={}; > $self->{connection}= X::connect($specs); > return undef unless defined $self->{$connection}; > bless ($self,$class); > return $self; > >B >sub new { > my $proto=shift; > my $specs=shift; > my $class=ref($proto) || $proto; > my $self={}; > $self->{X} = X->new(); > $self->{connection}= $self->{X}->{connection}; > return undef unless defined $self->{$connection}; > bless ($self,$class); > return $self; -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cgi & syslog
Hi all, I'm writing a simple perl cgi script to populate some infomation from syslog file, open FILE, " | tail /var/log/daemon.log"; but always got permission denied, no matter what i do about $>, $< Does anybody know how to access root owned file via cgi script? Thank in advance Frank -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
I have a list of Directories and FIles, how do I sort them out
Hello, I have a listing of directories and files in a root directory which I need to recreate at another Windows NT DOS shell machine. The alogrithm I have implemented in general works like this: # check if the listing exist in target machine # if exist, check if it is a file in target machine # if file, copy file over existing file in target # if directory, ignore # if not exist, check if it is a file in source directory # if file, create directory path and copy file to target # if directory, create directory only I am using the -e and -f test. Something is jinking the test and the -f does not work, so all my files always end up as directories in the target. What's wrong? Or is there a better way? TIA. Vincent -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Converting into exe
Junaid Najamuddin wrote: > Hi, > > Can anyone tell me the procedure in detail please > how to convert a Perl script into an executable > > Thanks > Junaid Check out IndigoStar Software. 'http://www.indigostar.com/perl2exe.htm' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
question from beginner
I'm trying to access log files on different Novell Servers. Path is \sys\arcserve.6\nwagent.txt Here is the problem and why I'm trying to do this with Perl. The log file is extensive, and is sorted by date. Example line: Aug-14 20:11:42 Job request from @ (NetWare Server) This is the first line of the log from the last night. This is where I want to start grabbing lines and appending them to another log. I've tried using the localtime function to determine the date and pipe it to a new variable that will read similar to "Aug-14" to begin my search of the file (nwagent.txt) with. I'm beginning to get stuck there, then I'm not sure how to open and read the file looking for and appending everything (entire line) that matches that string. Thanks in advance for any help or direction that can be given. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cgi & syslog
>Does anybody know how to access root owned file via cgi script? Not unless your webserver (which runs the cgi script with its own permissions) is set as root, and that's normally a big no-no. There is a Syslog module though - you may want to look into that (I know nothing about it, though)... -- Morbus Iff ( i am your scary godmother ) http://www.disobey.com/ && http://www.gamegrene.com/ please me: http://www.amazon.com/exec/obidos/wishlist/25USVJDH68554 icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: I have a list of Directories and FIles, how do I sort them out
It might be helpful if you posted at least the part of the code that is having trouble. it's difficult to say what went wrong when we can't really see what is even happening. Steve H. -Original Message- From: Vincent Lim [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 9:35 AM To: [EMAIL PROTECTED] Subject: I have a list of Directories and FIles, how do I sort them out Hello, I have a listing of directories and files in a root directory which I need to recreate at another Windows NT DOS shell machine. The alogrithm I have implemented in general works like this: # check if the listing exist in target machine # if exist, check if it is a file in target machine # if file, copy file over existing file in target # if directory, ignore # if not exist, check if it is a file in source directory # if file, create directory path and copy file to target # if directory, create directory only I am using the -e and -f test. Something is jinking the test and the -f does not work, so all my files always end up as directories in the target. What's wrong? Or is there a better way? TIA. Vincent -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question from beginner
With only one line from a logfile to work with, I have to do a little guessing about format, but if all lines are formatted like that one, and if days always have a two digit format, and if a lot of other assumptions, This snippet does what you are looking to do: my ($mon, $mday) = (localtime(time))[4, 3]; my @monarray = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec}; ($mon, $mday) = ($monarray[$mon], (sprintf "%02d", $mday)); open (infile, "c:/blah/logfile.txt") || die "$!\n"; # open logfile #now create a new logfile: open (outfile, ">c:/blah/${mon}-${mday}_newfile.txt") || die "$!\n"; foreach () {#process the full log print outfile "$_" if (substr($_, 0, 6) eq "${mon}-${mday}"); } That is only going to work if you are searching for current day's entries. If you need to search for yesterday's entries, or take input for how many days etc. you'll have to work on the date searched for, but I might recommend that you look at the Date::Calc module if you have much more than a very simple date evaluation. Does this answer the several questions you asked? Of course, there is more than one way to do it. Steve H. -Original Message- From: Corey Epps [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 15, 2001 2:55 PM To: [EMAIL PROTECTED] Subject: question from beginner I'm trying to access log files on different Novell Servers. Path is \sys\arcserve.6\nwagent.txt Here is the problem and why I'm trying to do this with Perl. The log file is extensive, and is sorted by date. Example line: Aug-14 20:11:42 Job request from @ (NetWare Server) This is the first line of the log from the last night. This is where I want to start grabbing lines and appending them to another log. I've tried using the localtime function to determine the date and pipe it to a new variable that will read similar to "Aug-14" to begin my search of the file (nwagent.txt) with. I'm beginning to get stuck there, then I'm not sure how to open and read the file looking for and appending everything (entire line) that matches that string. Thanks in advance for any help or direction that can be given. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
file date checking
i need to remove files that are more than 30 days old. I know the foreach loop part but my if statement is not working. See below. #!/usr/bin/perl use File::stat; use File::Find; $dirname="/opt/ilbackup/status"; opendir(DIR, $dirname) or die "can't opendir $dirname: $!"; while ( defined ( $filename = readdir(DIR))) { unlink $filename if -f $filename and -M $filename > 31 ; }; closedir(DIR); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Calculation the total of my column
List, I have a problem here that I am having a little bit of trouble trying to resolve. Firstly I have a Perl script that connects to a PostgreSQL database using the DBI module. I want to be able to SELECT a column from the database and return the total result. For example if I do the following... $sth = $dbh ->prepare( qq{ SELECT minutes FROMtable WHERE status = 'COMPLETE' } ) || die $dbh->errstr; ; $sth->execute; The minutes attribute is of type integer. I want to be able to calculate the total for the attribue minutes. So far the result for the SQL query above is... minutes 30 45 5 5 15 25 15 5 25 25 (10 rows) How would I with Perl now count the column above and return a result? Any ideas would help imensly. kind regards, Daniel Falkenberg == VINTEK CONSULTING PTY LTD (ACN 088 825 209) Email: [EMAIL PROTECTED] WWW:http://www.vintek.net Tel:(08) 8523 5035 Fax:(08) 8523 2104 Snail: P.O. Box 312 Gawler SA 5118 == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
(Answer to my own question) RE: Calculation the total of my column
Dan, :) $sth = $dbh ->prepare( qq{ SELECT SUM(time_track_minutes) FROM table WHERE status = 'COMPLETE' } ) || die $dbh->errstr; ; $sth->execute; Regards, Daniel Falkenberg List, I have a problem here that I am having a little bit of trouble trying to resolve. Firstly I have a Perl script that connects to a PostgreSQL database using the DBI module. I want to be able to SELECT a column from the database and return the total result. For example if I do the following... $sth = $dbh ->prepare( qq{ SELECT minutes FROMtable WHERE status = 'COMPLETE' } ) || die $dbh->errstr; ; $sth->execute; The minutes attribute is of type integer. I want to be able to calculate the total for the attribue minutes. So far the result for the SQL query above is... minutes 30 45 5 5 15 25 15 5 25 25 (10 rows) How would I with Perl now count the column above and return a result? Any ideas would help imensly. kind regards, Daniel Falkenberg == VINTEK CONSULTING PTY LTD (ACN 088 825 209) Email: [EMAIL PROTECTED] WWW:http://www.vintek.net Tel:(08) 8523 5035 Fax:(08) 8523 2104 Snail: P.O. Box 312 Gawler SA 5118 == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Calculation the total of my column
I would do it like this (taking a stab at this...critique is welcomed): At 03:17 PM 08.16.2001 +0930, Daniel Falkenberg wrote: >List, > >I have a problem here that I am having a little bit of trouble trying to >resolve. Firstly I have a Perl script that connects to a PostgreSQL >database using the DBI module. I want to be able to SELECT a column from >the database and return the total result. > >For example if I do the following... > >$sth = $dbh ->prepare( qq{ SELECT minutes >FROMtable >WHERE status = 'COMPLETE' >} ) || die $dbh->errstr; ; >$sth->execute; my $total = 0; map { $total = $total + $_ } $sth->execute; print "The sum of the minutes is: $total\n"; I THINK that would work. I am still somewhat new to Perl myself so if someone could validate that for me I'd appreciate it. I am assuming (now probably I shouldn't have buuut porting this shouldn't be hard) that your resulting query returns just the minutes. If it doesn't, then you will have to isolate those minutes into a list or array. Then you can do the same thing as above but you would want to replace the '$sth->execute;' with '@YOUR_ARRAY' in the map statement. Remember, map{} is your friend. :) Thanks everyone IA. - Jim >The minutes attribute is of type integer. I want to be able to calculate >the total for the attribue minutes. So far the result for the SQL query >above is... > >minutes > >30 >45 > 5 > 5 >15 >25 >15 > 5 >25 >25 >(10 rows) > > >How would I with Perl now count the column above and return a result? > >Any ideas would help imensly. > >kind regards, > >Daniel Falkenberg > >== >VINTEK CONSULTING PTY LTD >(ACN 088 825 209) >Email: [EMAIL PROTECTED] >WWW:http://www.vintek.net >Tel:(08) 8523 5035 >Fax:(08) 8523 2104 >Snail: P.O. Box 312 > Gawler SA 5118 >== > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - Jim -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861 -BEGIN PERL GEEK CODE BLOCK- --BEGIN GEEK CODE BLOCK-- Version: 0.01 Version: 3.12 P++>*@$c?P6?R+++>@$M GIT/CM/J d++(--) s++:++ a- >$O!MA->E!> PU-->+++BDC(+) UB$L$S$ $C-@D!>(-)$S@$X?WP+>MO!>+++ P++(+)>+ L+++()>+$ !E* +PP+++>n-CO?PO!o >G W++(+++) N+ o !K w--- PS---(-)@ PE >*(!)$A-->@$Ee---(-)Ev++uL++>*@$uB+ Y+>+++ PGP t+(+++)>+++@ 5- X++ R@ >*@$uS+>*@$uH+uo+w-@$m! tv+ b? DI-(+++) D+++(++) G() --END PERL GEEK CODE BLOCK-- --END GEEK CODE BLOCK-- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Calculation the total of my column
If all you want to do is get a total of all the minutes in the table, work smarter, not harder. Let SQL do the work for you. In your select statement you will want to use the function sum. So something like so: $sth = $dbh ->prepare( qq{ SELECT sum(minutes) FROMtable WHERE status = 'COMPLETE' } ) || die $dbh->errstr; ; After execution, the query will return one row and one column with the sum of all the minutes that meet the conditional. Hope this helps. Peter Hanson -Database Administrator -Programmer -Marketing Manager Want to make your traffic explode and your website a success? http://www.source1results.com -Original Message- From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 16, 2001 1:47 AM To: Beginners (E-mail) Subject: Calculation the total of my column List, I have a problem here that I am having a little bit of trouble trying to resolve. Firstly I have a Perl script that connects to a PostgreSQL database using the DBI module. I want to be able to SELECT a column from the database and return the total result. For example if I do the following... $sth = $dbh ->prepare( qq{ SELECT minutes FROMtable WHERE status = 'COMPLETE' } ) || die $dbh->errstr; ; $sth->execute; The minutes attribute is of type integer. I want to be able to calculate the total for the attribue minutes. So far the result for the SQL query above is... minutes 30 45 5 5 15 25 15 5 25 25 (10 rows) How would I with Perl now count the column above and return a result? Any ideas would help imensly. kind regards, Daniel Falkenberg == VINTEK CONSULTING PTY LTD (ACN 088 825 209) Email: [EMAIL PROTECTED] WWW:http://www.vintek.net Tel:(08) 8523 5035 Fax:(08) 8523 2104 Snail: P.O. Box 312 Gawler SA 5118 == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]