Re: Error opening file?
Hi Billy, can't see anything wrong with the code, except that it assumes that the file is in the current directory. It's not something as daft as you 'cd'ing to that directory before you ran in debug mode is it? Gary On Friday 27 April 2001 3:44 am, Billy Joedono wrote: > Hi all, > > Below is a piece of code central to my problem. I've used this a lot > of time without problem, but on this occasion, it fails me. Whenever > I run the script, it ends with the error "bash: ./test.pl: No such > file or directory". The funny thing is, if I activate the debug > option (use #!/usr/bin/perl -d) and step through the code, it does > what I want, no errors given there. > > Can somebody points me to the cause of this? Seeing that it works > when debugged suggests that it is not permission problem, or is it? I > know it's going to be something simple that I miss. Anyway, I am > using Red Hat 6.2 and perl 5.005_03. > > > #!/usr/bin/perl > open (FLT, "once_filter.txt") || warn "can not open filter file: $!"; > while () { > # chomp; >$Filter= $_; >printf "Search filter is $Filter\n"; > > snip ... > > } > close (FLT) || warn "can not close filter file: $!"; > > > > * >** Thanks and regards, > Billy Joedono > > "Courtesy comes by default, but respect I gotta earn" > * >** -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
Re: Error opening file? - Solved!
Hi Billy, unix2dos #!/usr/local/bin/perl -w while () { chomp; if ( $0=~m/dos2unix$/ ) { print "$_\n"; } else { print "$_\r\n"; } } dos2unix #!/usr/local/bin/perl -w while () { chomp; if ( $0=~m/dos2unix$/ ) { print "$_\n"; } else { print "$_\r\n"; } } On Friday 27 April 2001 7:43 am, Billy Joedono wrote: > Hi, > > Thanks to all who commented. They are all correct. John Joseph's > suggestion to use #!/usr/bin/per; -w would work too. But Jason's > suggestion below pointed me to the solution. When the command perl > test.pl work, right there I realize file format might be suspect. I > pulled out my HEX editor and there they were, the pairs. I > didn't show in Linux vi the way it would in Solaris vi, neither would > it in the GNU editor (which I use). Convert to regular Unix format > and problem solved! More question: how can I force vi to show these, > or better yet, how can I get dos2unix or unix2dos in Linux? > > The down-side of Linux understanding much of Windowz is that you > never get subjected to these little finicky differences until you're > struck by them. > > At 01:24 PM 4/27/2001 +1000, King, Jason wrote: > >can you run it manually by passing it to the interpreter > > > > perl test.pl > > > >? > > > > > >-- > > jason king > > > > A Canadian law states that citizens may not publicly remove > > bandages. - http://dumblaws.com/ > > * >** Thanks and regards, > Billy Joedono > > "Courtesy comes by default, but respect I gotta earn" > * >** -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
Error.pm
Hellows I've donwloaded a module from CPAN (CORBA::ORBit) but it requires Error ('require Error') and there is any Error.pm in the system. Can anybody explain what can I do to put it working? I think removing the line will do the trick, but I would like to know what's this require Error purpose. Ho, I'm using perl 5.6.0. Alberto -- | Alberto Manuel Brandão Simões | | [EMAIL PROTECTED] | | http://numexp.sourceforge.net |
MySQL Blobs DBI & CGI
Hi, I am currently trying to get perl and mysql talking together on linux. I have succeeded in the basics, doing selects, inserts, updates and deletes when dealing with chars and ints. I have now turned my attention to blobs, and am having considerable difficulty. I have managed to get a blob(a jpeg file) from a local file on the linux box into the database, but I can't seem to get the thing back out and onto a webpage! I have scanned numerous lists and books, but seem to be unable to find any real information on dealing with blobs. Can anyone point me in the right direction ? Thanks very much for you time Edd Dawson
Re: Error opening file?
Billy Joedono ([EMAIL PROTECTED]) wrote: > Hi all, > > Below is a piece of code central to my problem. I've used this a lot of > time without problem, but on this occasion, it fails me. Whenever I run the > script, it ends with the error "bash: ./test.pl: No such file or > directory". That's not a perl problem, the error comes from your shell. Does your perl really sit in '/usr/bin/perl' as your she-bang says? -- sample 1 -- kanku-dai:~$ head -1 check.pl #!/usr/bin/perl kanku-dai:~$ ./check.pl can not open filter file: No such file or directory at ./check.pl line 2. can not close filter file: Bad file descriptor at ./check.pl line 11. kanku-dai:~$ -- sample 1 -- Now changing the header: -- sample 1 -- kanku-dai:~$ head -1 check.pl #!/usr/bin/nothing-here kanku-dai:~$ !./ ./check.pl bash: ./check.pl: No such file or directory kanku-dai:~$ -- sample 2 -- That's exactly the message you're seeing. The shell can't find the specified interpreter. Are you sure you're not debugging via perl -d yourscript.pl In that case everything works, since your perl is most probably in the PATH. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: CPAN Question
Phillip Bruce ([EMAIL PROTECTED]) wrote: > Hi, > > Sometime back some one gave me the path to a config file in > which told cpan where and what compilers that my systems > uses. > Does anyone have any ideas to this. > > I get this error: > /usr/ucb/cc: language optional software package not > installed > > That is because I'm not using cc but gcc instead and I have > the > CC environment variable set to gcc. Is the variable really exported? Try perl Makefile.PL CC=gcc instead. I remember having a Makefile.PL that explicitely overruled the environment variable by using the compiler that perl was built with. You can check which compiler that is with the command perl -lMConfig -e 'print $Config{cc}' Finally, is the gcc compiler really in the PATH? Remember that you can lose settings depending on how you 'su' yourself. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
replacing an element in an array
Am rather a beginner at perl and was wondering how to do the following. I've read in a text file containing a list of file paths. the list is read in to an array. I want to scan through the whole array and remove all lines with end as .txt and .scc. i.e remove that element in the array. My file list looks like this: D:\Liberate\Connect\app\pages\servicemanager\splash.gif D:\Liberate\Connect\app\pages\servicemanager\splash.html D:\Liberate\Connect\app\pages\servicemanager\vssver.scc D:\Liberate\Connect\app\pages\servicemanager\sounds\enter.wav D:\Liberate\Connect\app\pages\servicemanager\sounds\key.wav D:\Liberate\Connect\app\pages\servicemanager\sounds\vssver.scc and my code thus far is: #\usr\local\bin\perl $file = 'flashimage.txt'; # Name the file open(INFO, $file); # Open the file @lines = ; # Read it into an array close(INFO); # Close the file foreach $eachline (@lines) { $eachline =~ s/scc//g } print @lines;
Re: replacing an element in an array
: Am rather a beginner at perl and was wondering how to do the following. I've : read in a text file containing a list of file paths. the list is read in to : an array. I want to scan through the whole array and remove all lines with : end as .txt and .scc. i.e remove that element in the array. My file list : looks like this: : : D:\Liberate\Connect\app\pages\servicemanager\splash.gif : D:\Liberate\Connect\app\pages\servicemanager\splash.html : D:\Liberate\Connect\app\pages\servicemanager\vssver.scc : D:\Liberate\Connect\app\pages\servicemanager\sounds\enter.wav : D:\Liberate\Connect\app\pages\servicemanager\sounds\key.wav : D:\Liberate\Connect\app\pages\servicemanager\sounds\vssver.scc grep() will do it easily: @lines = grep { ! /\.txt$|\.scc$/ } @lines; or do it when you read the file: @lines = grep { ! /\.txt$|\.scc$/ } ; -- Tim Kimball · ACDSD / MAST¦ Space Telescope Science Institute ¦ We are here on Earth to do good to others. 3700 San Martin Drive ¦ What the others are here for, I don't know. Baltimore MD 21218 USA¦ -- W.H. Auden
Re: replacing an element in an array
Hi Kaustav, You can do something such as: #!/usr/bin/perl -w use strict; my $file = "foo.file"; open(FILE, $file) or die "Can't open $file: $!"; my @lines= ; close FILE; @lines = grep {!/\.(txt|scc)$/} @lines; print qq{$_\n} for @lines; This isn't "deleting" from the array, rather reforming it. Cheers, Kevin On Fri, Apr 27, 2001 at 01:25:40PM +0100, Kaustav Bhattacharya ([EMAIL PROTECTED]) spew-ed forth: > Am rather a beginner at perl and was wondering how to do the following. I've > read in a text file containing a list of file paths. the list is read in to > an array. I want to scan through the whole array and remove all lines with > end as .txt and .scc. i.e remove that element in the array. My file list > looks like this: > > D:\Liberate\Connect\app\pages\servicemanager\splash.gif > D:\Liberate\Connect\app\pages\servicemanager\splash.html > D:\Liberate\Connect\app\pages\servicemanager\vssver.scc > D:\Liberate\Connect\app\pages\servicemanager\sounds\enter.wav > D:\Liberate\Connect\app\pages\servicemanager\sounds\key.wav > D:\Liberate\Connect\app\pages\servicemanager\sounds\vssver.scc > > > and my code thus far is: > > #\usr\local\bin\perl > > $file = 'flashimage.txt'; # Name the file > open(INFO, $file); # Open the file > @lines = ; # Read it into an array > close(INFO); # Close the file > > foreach $eachline (@lines) { > $eachline =~ s/scc//g > } > > print @lines; > > -- [Writing CGI Applications with Perl - http://perlcgi-book.com] The difference between whining and advocacy is great. It took me seven years to figure that out. -- Michael J. Fox
CR LF
Billy, I do a lot of Perl on an NT box that eventually gets used in both NT and Debian. It was pretty frustrating at first, experiencing your problem. A nice little one-liner that I use after taking a script from NT to a linux system is: perl -w -i -p -e "s/\x0d//g" filename Stephen Neu Internet Development Characterlink.net "What is so difficult for developers to accept sometimes is that there already is a standard, and they didn't write it." --Steve Neu
Perl regex to C
Hi, I know you can run C programs from perl. I know you can run perl programs from C. My question is, is there a perl script (or any software) that is able to convert perl regex into valid C code ? Perl is wonderful for matching expression, some software I have to deal with in C would benefit a lot from these regex; it would be great if I could write the regex is perl, and convert it into C, pasting the resulting code into a function in my C program. Obviously I could also use a regex library for C but I would prefer to avoid that. Thanks, -Robin
Re: replacing an element in an array
On Fri, Apr 27, 2001 at 08:32:21AM -0400, Timothy Kimball ([EMAIL PROTECTED]) spew-ed forth: > > grep() will do it easily: > > @lines = grep { ! /\.txt$|\.scc$/ } @lines; > > or do it when you read the file: > > @lines = grep { ! /\.txt$|\.scc$/ } ; You are making the RE engine do a log of work there. [root@fluffhead /root]# perl -Mre=debug -wle '$_=qq{foo.txt}; /\.(txt|foo)$/'; Compiling REx `\.(txt|foo)$' size 14 first at 1 1: EXACT <.>(3) 3: OPEN1(5) 5: BRANCH(8) 6: EXACT (11) 8: BRANCH(11) 9: EXACT (11) 11: CLOSE1(13) 13: EOL(14) 14: END(0) anchored `.' at 0 (checking anchored) minlen 4 Guessing start of match, REx `\.(txt|foo)$' against `foo.txt'... Found anchored substr `.' at offset 3... Guessed: match at offset 3 Matching REx `\.(txt|foo)$' against `.txt' Setting an EVAL scope, savestack=3 3 <.txt> | 1: EXACT <.> 4 | 3: OPEN1 4 | 5: BRANCH Setting an EVAL scope, savestack=3 4 | 6:EXACT 7 <> | 11:CLOSE1 7 <> | 13:EOL 7 <> | 14:END Match successful! Freeing REx: `\.(txt|foo)$' versus: [root@fluffhead /root]# perl -Mre=debug -wle '$_=qq{foo.txt}; /\.txt$|\.foo$/' Compiling REx `\.txt$|\.foo$' size 9 1: BRANCH(5) 2: EXACT <.txt>(4) 4: EOL(9) 5: BRANCH(9) 6: EXACT <.foo>(8) 8: EOL(9) 9: END(0) minlen 4 Matching REx `\.txt$|\.foo$' against `foo.txt' Setting an EVAL scope, savestack=3 0 <> | 1: BRANCH Setting an EVAL scope, savestack=3 0 <> | 2:EXACT <.txt> failed... 0 <> | 6:EXACT <.foo> failed... failed... Setting an EVAL scope, savestack=3 1 | 1: BRANCH Setting an EVAL scope, savestack=3 1 | 2:EXACT <.txt> failed... 1 | 6:EXACT <.foo> failed... failed... Setting an EVAL scope, savestack=3 2 | 1: BRANCH Setting an EVAL scope, savestack=3 2 | 2:EXACT <.txt> failed... 2 | 6:EXACT <.foo> failed... failed... Setting an EVAL scope, savestack=3 3 <.txt> | 1: BRANCH Setting an EVAL scope, savestack=3 3 <.txt> | 2:EXACT <.txt> 7 <> | 4:EOL 7 <> | 9:END Match successful! Freeing REx: `\.txt$|\.foo$' When you look at /\.txt$|\.foo$/ you see what the RE engine is doing (much easier to see if you use -Mre=debugcolor). It tries to match in portions; foo.txt -> oo.txt -> o.txt -> .txt -> (if all failed) foo.foo -> oo.foo -> o.foo -> .foo The first one immediately sees the anchor, and tries to match less patterns; txt -> (if failed) foo A really good book to read is Mastering Regular Expressions, if you are new to regular expressions (of course, read perlre), and a great article on how the RE engine works is at http://perl.plover.com/Regex/article.html Cheers, Kevin -- [Writing CGI Applications with Perl - http://perlcgi-book.com] It would be easier to pay off the national debt overnight than to neutralize the long-range effects of OUR NATIONAL STUPIDITY. -- Frank Zappa
Re: replacing an element in an array
: You are making the RE engine do a log of work there. You're right, your way is better. I tend to write code that is clear to the way I think and then optimize it later (usually with a profiler). Should get more in the habit of "use re 'debug'". -- tdk
RE: replacing an element in an array
Others have given you some good stuff about deleting from the array, but what about if you try a different approach and filter the files as you add them to the array? #!/usr/local/bin/perl $file = 'flashimage.txt'; # file name @lines = ();# init empty array open(INFO, $file) or die $! # file open w/error check while() { push @lines, $_ # <-- no semicolon! if /\.(txt|scc)$/; # shorthand "if" test } close INFO; print (join "\n", @lines); # print files, one per line Like that any better? :) Mark Nutter Manager, Internet Applications Development Marconi [EMAIL PROTECTED] It's not necessarily an advantage to have better brakes than the guy behind you. > -Original Message- > From: Kaustav Bhattacharya [mailto:[EMAIL PROTECTED]] > Sent: Friday, April 27, 2001 8:26 AM > To: [EMAIL PROTECTED] > Subject: replacing an element in an array > > > Am rather a beginner at perl and was wondering how to do the > following. I've > read in a text file containing a list of file paths. the > list is read in to > an array. I want to scan through the whole array and remove > all lines with > end as .txt and .scc. i.e remove that element in the array. > My file list > looks like this: > > D:\Liberate\Connect\app\pages\servicemanager\splash.gif > D:\Liberate\Connect\app\pages\servicemanager\splash.html > D:\Liberate\Connect\app\pages\servicemanager\vssver.scc > D:\Liberate\Connect\app\pages\servicemanager\sounds\enter.wav > D:\Liberate\Connect\app\pages\servicemanager\sounds\key.wav > D:\Liberate\Connect\app\pages\servicemanager\sounds\vssver.scc > > > and my code thus far is: > > #\usr\local\bin\perl > > $file = 'flashimage.txt'; # Name the file > open(INFO, $file); # Open the file > @lines = ; # Read it into an array > close(INFO); # Close the file > > foreach $eachline (@lines) { > $eachline =~ s/scc//g > } > > print @lines; > >
Error
Hi, I'm getting the following errror: Global symbol "$fh" requires explicit package name at livonia.pl line 22. Execution of livonia.pl aborted due to compilation errors. Also can some one suggest a better way to handle the IO I'm wondering about the globtype and that is why I used the \*FH in my subroutine. Below is the code: #!/usr/bin/perl # Modules use strict; use Text::CSV_XS; use FileHandle; # Constants my $datafile = 'everyone.csv'; #my $summary = 'summary.txt'; #open $handle, "$datafile" or die "$datafile: $!"; sub newopen { my $path = shift; local *FH; open (FH, $path) || return undef; return \*FH; } $fh = newopen("$datafile"); my $csv = Text::CSV_XS->new; my $column = ''; if ($csv->parse($fh)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } my @sample_input_fields = ('You said, "Hello!"', 5.67, 'Surely', '', '3.14159'); if ($csv->combine(@sample_input_fields)) { my $string = $csv->string; print $string, "\n"; } else { my $err = $csv->error_input; print "combine() failed on argument: ", $err, "\n"; } #close(INFILE); #close(OUTFILE); -- *** Phillip B. Bruce *** *** http://pbbruce.home.mindspring.com *** *** [EMAIL PROTECTED] *** *** *** *** "Have you ever noticed? Anybody going slower than*** *** you is an idiot, and anyone going faster than you*** *** is a maniac." - George Carlin***
RE: Error
$fh = newopen("$datafile"); It looks like this line needs a 'my' -Original Message- From: Phillip Bruce [mailto:[EMAIL PROTECTED]] Sent: Friday, April 27, 2001 7:47 AM To: perl Subject: Error Hi, I'm getting the following errror: Global symbol "$fh" requires explicit package name at livonia.pl line 22. Execution of livonia.pl aborted due to compilation errors. Also can some one suggest a better way to handle the IO I'm wondering about the globtype and that is why I used the \*FH in my subroutine. Below is the code: #!/usr/bin/perl # Modules use strict; use Text::CSV_XS; use FileHandle; # Constants my $datafile = 'everyone.csv'; #my $summary = 'summary.txt'; #open $handle, "$datafile" or die "$datafile: $!"; sub newopen { my $path = shift; local *FH; open (FH, $path) || return undef; return \*FH; } $fh = newopen("$datafile"); my $csv = Text::CSV_XS->new; my $column = ''; if ($csv->parse($fh)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } my @sample_input_fields = ('You said, "Hello!"', 5.67, 'Surely', '', '3.14159'); if ($csv->combine(@sample_input_fields)) { my $string = $csv->string; print $string, "\n"; } else { my $err = $csv->error_input; print "combine() failed on argument: ", $err, "\n"; } #close(INFILE); #close(OUTFILE); -- *** Phillip B. Bruce *** *** http://pbbruce.home.mindspring.com *** *** [EMAIL PROTECTED] *** *** *** *** "Have you ever noticed? Anybody going slower than*** *** you is an idiot, and anyone going faster than you*** *** is a maniac." - George Carlin***
Re: Error
: Global symbol "$fh" requires explicit package name at : livonia.pl line 22. : Execution of livonia.pl aborted due to compilation errors. You have "use strict" turned on, so put "my" in front of $fh in line 22. to give it scope. "strict" would rather you didn't use globals. : Also can some one suggest a better way to handle the IO I'm : wondering about : the globtype and that is why I used the \*FH in my subroutine. Take a look at the FileHandle module, which comes with Perl: % perldoc FileHandle -- Tim Kimball · ACDSD / MAST¦ Space Telescope Science Institute ¦ We are here on Earth to do good to others. 3700 San Martin Drive ¦ What the others are here for, I don't know. Baltimore MD 21218 USA¦ -- W.H. Auden
Re: [BPQ] help!! any idea whats wrong with this??
Neato & thanks. I don't understand why one solution uses map & count and the other just uses count. Is map implied in the second solution? - Original Message - From: "Paul" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "Bill Lawry" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, April 26, 2001 6:59 PM Subject: Re: [BPQ] help!! any idea whats wrong with this?? > > --- Paul <[EMAIL PROTECTED]> wrote: > > > > --- Bill Lawry <[EMAIL PROTECTED]> wrote: > > > Pretty cool but when used on a file it breaks hyphenated words into > > > their components and counts them separately: > > > > > > 17 occurrences of 'Acct' > > > 3 occurrences of 'Authentic' > > > etc > > > > > > instead of: > > > > > > 3 occurrences of Acct-Authentic > > > 3 occurrences of Acct-Delay-Time > > > 1 occurrences of Acct-Input-Octets > > > 1 occurrences of Acct-Input-Packets > > > 1 occurrences of Acct-Output-Octets > > > 1 occurrences of Acct-Output-Packets > > > 3 occurrences of Acct-Session-Id > > > 1 occurrences of Acct-Session-Time > > > 3 occurrences of Acct-Status-Type > > > > Not what you want? Then let's edit the pattern. =o) > > > > Instead of > > map { $count{$_}++ } $data =~ /(\w+)/sog; > > > > try > >$count{$_}++ } for $data =~ /([\w-]+)/sog; > > ps^Make that: > > $count{$_}++ for $data =~ /([\w-]+)/sog; > > > > > - Original Message - > > > From: "Michael Lamertz" <[EMAIL PROTECTED]> > > > To: <[EMAIL PROTECTED]> > > > Cc: "Chris Brown" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > > Sent: Tuesday, April 24, 2001 1:03 PM > > > Subject: Re: [BPQ] help!! any idea whats wrong with this?? > > > > > > > > > > Paul ([EMAIL PROTECTED]) wrote: > > > > > > > > > > #!/usr/local/bin/perl -w > > > > > > > > > > use strict > > > > > open (FILE,$0) or die $!; # this reads itself > > > > > my($data,%count); > > > > > { local $/ = undef; # erases the record seperator for > > this > > > block > > > > >$data = ; # slurps in the whole file to $data > > > > > } > > > > > close(FILE); # good habit > > > > > map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the context! > > > > > print map { "$count{$_} occurances of '$_'\n" } sort keys > > > %count; > > > > > > > > > > Perl is a wonderfully concise language. > > > > > The above is strictly given as an example of a few performance > > > tricks > > > > > that are worth researching. =o) > > > > > > > > I agree printing the map output, but I disagree using map to > > > calculate > > > > the sums. map always generates a new array that immediately gets > > > dumped > > > > since it's not assigned. A foreach would be nicer to system > > > resources > > > > and better to read. To make it short, use it postfix: > > > > > > > > $count{$_}++ foreach ($data=~ /.../); > > > > > > > > Check 'perldoc perlfaq6' for reference. > > > > > > > > -- > > > > If we fail, we will lose the war. > > > > > > > > Michael Lamertz | [EMAIL PROTECTED] / > > > [EMAIL PROTECTED] > > > > Nordstr. 49 | http://www.lamertz.net > > > > 50733 Cologne| Work: +49 221 3091-121 > > > > Germany | Priv: +49 221 445420 / +49 171 6900 > > 310 > > > > > > > > > > > > > __ > > Do You Yahoo!? > > Yahoo! Auctions - buy the things you want at great prices > > http://auctions.yahoo.com/ > > > __ > Do You Yahoo!? > Yahoo! Auctions - buy the things you want at great prices > http://auctions.yahoo.com/ >
Komodo
Some of you may be interested in Komodo... http://www.activestate.com/ASPN/ It's a GUI IDE for Perl (and Python and other unmentionables :). The "Visible Regex" stuff is pretty cool for playing around. You have to join ActiveState Programmers Network (ASPN), but it's free, and comes with a free Komodo license. From what I've seen of it, it looks fairly useful, especially for beginners. Mark Nutter Manager, Internet Applications Development Marconi [EMAIL PROTECTED] It's not necessarily an advantage to have better brakes than the guy behind you.
Re: Error: Runtime Exception
--- "Arante, Susan" <[EMAIL PROTECTED]> wrote: > This used to be working but after my very adventurous fiasco > (deleting perl5, installing perl6, deleting perl6, installing perl5 - > yes i deleted not uninstalled), it's not working anymore. I'm running > perl5 on NT. I'd try installing Perl5, then uninstalling, then installing Perl6, then uninstalling, then installing Perl6. Hey, it could work, lol Sorry. I don't imagine you think it's very funny. =o) But I really have had that sort of thing work. > I'm getting the above error when my perl script runs a batch > (master.bat) > that in turn runs a batch (slave.bat) that runs another perl script. > > The process kicks me out What do you mean, "kicks me out"? Do you have any error reporting? >--- > Script goes like this: > open(CFGFILE, "ReStart_one.cfg")); Two close parens?-^ > open(MASTERBAT, ">Master.bat"); Add "or die" to each. open CFGFILE, "ReStart_one.cfg" or die "ReStart_one.cfg: $!"; open MASTERBAT, ">Master.bat" or die "Master.bat: $!"; > $mcname = ; > while ($mcname ne "") { Just since I can't see the rest of the script, is there a reason you didn't just use while($mcname=) { That would preinitialize before the first loop iteration, and would fall out of the loop at EOF (when it returned undef). Also, in case you aren't, try these to help your error reporting: use strict; use diagnostics; enable diagnostics; and run perl with the -w flag. > chomp($mcname); > printf MASTERBAT ("Start slave.bat $mcname\n"); > printf MASTERBAT ("wait 5\n"); Don't use printf unless you really need it. print is faster and more stable, or so I seem to remember reading in the docs somewhereyup. >From perldoc -f printf: printf FILEHANDLE FORMAT, LIST printf FORMAT, LIST Equivalent to `print FILEHANDLE sprintf(FORMAT, LIST)', except that `$\' (the output record separator) is not appended. The first argument of the list will be interpreted as the `printf' format. If `use locale' is in effect, the character used for the decimal point in formatted real numbers is affected by the LC_NUMERIC locale. See the perllocale manpage. ==>> Don't fall into the trap of using a `printf' when a simple `print' would do. The `print' is more efficient and less error prone. > NEXTMC:$mcname = ; > } > close MASTERBAT; > printf `master.bat`; Check $? and $! after this runs: print "master.bat returned $? $!\n"; > > Master.bat has these lines: > Start slave.bat CHITMD03 > wait 5 > Start slave.bat CHITMD19 > wait 5 > Start slave.bat CHITMP03 > wait 5 Assuming these are DOS-ish, though I'm not familiar with batch commands since about DOS6.2; I'm assuming Start is analogous to the call command, which runs a batch file and arranges to return to the current script afterwards (which wasn't the default last time I wrote a batch file), or perhaps is NT's way of putting a script into the background?. I also assume wait does what it does in UNIX, which is to wait (doh), usually for a background process. > --- > Slave.bat calls a perl script that stops and starts certain services > on the server. > --- > The whole process runs fine if I only have one machine listed in cfg. > It dies and kicks me out right before master.bat when I have more > than one machine in cfg. Any clues? Btw, I removed some lines to > simplify script (I may have chopped it too much!)... Good luck. > tia.. > Susan __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Re: [BPQ] help!! any idea whats wrong with this??
--- Bill Lawry <[EMAIL PROTECTED]> wrote: > Neato & thanks. > > I don't understand why one solution uses map & count and the other > just uses count. Is map implied in the second solution? Because someone (and with apologies to all, I don't recall off the top of my head who)correctly pointed out to me earlier in this thread that using map() here was inefficient. map() builds and returns an array, so there's no point in using it in this void context. Aside from that, both do the same thing. The postfix for is cleaner. =o) > > > map { $count{$_}++ } $data =~ /(\w+)/sog; > > $count{$_}++ for $data =~ /([\w-]+)/sog; btw, "foreach" might have been more readable here, but "foreach" is pretty much an alias to "for", which is fewer characters to type ~wink~ > - Original Message - > From: "Paul" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]>; "Bill Lawry" <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Thursday, April 26, 2001 6:59 PM > Subject: Re: [BPQ] help!! any idea whats wrong with this?? > > > > > > --- Paul <[EMAIL PROTECTED]> wrote: > > > > > > --- Bill Lawry <[EMAIL PROTECTED]> wrote: > > > > Pretty cool but when used on a file it breaks hyphenated words > into > > > > their components and counts them separately: > > > > > > > > 17 occurrences of 'Acct' > > > > 3 occurrences of 'Authentic' > > > > etc > > > > > > > > instead of: > > > > > > > > 3 occurrences of Acct-Authentic > > > > 3 occurrences of Acct-Delay-Time > > > > 1 occurrences of Acct-Input-Octets > > > > 1 occurrences of Acct-Input-Packets > > > > 1 occurrences of Acct-Output-Octets > > > > 1 occurrences of Acct-Output-Packets > > > > 3 occurrences of Acct-Session-Id > > > > 1 occurrences of Acct-Session-Time > > > > 3 occurrences of Acct-Status-Type > > > > > > Not what you want? Then let's edit the pattern. =o) > > > > > > Instead of > > > map { $count{$_}++ } $data =~ /(\w+)/sog; > > > > > > try > > >$count{$_}++ } for $data =~ /([\w-]+)/sog; > > > > ps^Make that: > > > > $count{$_}++ for $data =~ /([\w-]+)/sog; > > > > > > > > - Original Message - > > > > From: "Michael Lamertz" <[EMAIL PROTECTED]> > > > > To: <[EMAIL PROTECTED]> > > > > Cc: "Chris Brown" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > > > Sent: Tuesday, April 24, 2001 1:03 PM > > > > Subject: Re: [BPQ] help!! any idea whats wrong with this?? > > > > > > > > > > > > > Paul ([EMAIL PROTECTED]) wrote: > > > > > > > > > > > > #!/usr/local/bin/perl -w > > > > > > > > > > > > use strict > > > > > > open (FILE,$0) or die $!; # this reads itself > > > > > > my($data,%count); > > > > > > { local $/ = undef; # erases the record seperator > for > > > this > > > > block > > > > > >$data = ; # slurps in the whole file to > $data > > > > > > } > > > > > > close(FILE); # good habit > > > > > > map { $count{$_}++ } $data =~ /(\w+)/sog; # watch the > context! > > > > > > print map { "$count{$_} occurances of '$_'\n" } sort keys > > > > %count; > > > > > > > > > > > > Perl is a wonderfully concise language. > > > > > > The above is strictly given as an example of a few > performance > > > > tricks > > > > > > that are worth researching. =o) > > > > > > > > > > I agree printing the map output, but I disagree using map to > > > > calculate > > > > > the sums. map always generates a new array that immediately > gets > > > > dumped > > > > > since it's not assigned. A foreach would be nicer to system > > > > resources > > > > > and better to read. To make it short, use it postfix: > > > > > > > > > > $count{$_}++ foreach ($data=~ /.../); > > > > > > > > > > Check 'perldoc perlfaq6' for reference. > > > > > > > > > > -- > > > > > If we fail, we will lose the war. > > > > > > > > > > Michael Lamertz | [EMAIL PROTECTED] / > > > > [EMAIL PROTECTED] > > > > > Nordstr. 49 | http://www.lamertz.net > > > > > 50733 Cologne| Work: +49 221 3091-121 > > > > > Germany | Priv: +49 221 445420 / +49 171 > 6900 > > > 310 > > > > > > > > > > > > > > > > > > __ > > > Do You Yahoo!? > > > Yahoo! Auctions - buy the things you want at great prices > > > http://auctions.yahoo.com/ > > > > > > __ > > Do You Yahoo!? > > Yahoo! Auctions - buy the things you want at great prices > > http://auctions.yahoo.com/ > > > __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Re: [BPQ] help!! any idea whats wrong with this??
: Because someone (and with apologies to all, I don't recall off the top : of my head who)correctly pointed out to me earlier in this thread that : using map() here was inefficient. map() builds and returns an array, so : there's no point in using it in this void context. Aside from that, : both do the same thing. The postfix for is cleaner. =o) I agree that the postfix is cleaner, but when I benchmark these, map looks faster- though several months ago, map was slower (IIRC). Maybe something changed in 5.6.0 to make map faster in a null context...? Here's the script & output (Perl 5.6.0 on an Ultra 10): archdev 10:58% more ./z #!/archive/data1/bin/perl use strict; use Benchmark; my @lines = qw( 10th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th a AAA AAAS Aarhus Aaron AAU ABA Ababa aback abacus ); timethese(500_000,{ "1. map" => 'map { s/a// } @lines', "2. foreach" => 'foreach ( @lines ) { s/a// }', "3. for" => 's/a// for @lines', }); archdev 10:58am 147% ./z Benchmark: timing 50 iterations of 1. map, 2. foreach, 3. for... 1. map: 0 wallclock secs ( 0.93 usr + 0.00 sys = 0.93 CPU) @ 537634.41/s (n=50) 2. foreach: 2 wallclock secs ( 2.29 usr + 0.00 sys = 2.29 CPU) @ 218340.61/s (n=50) 3. for: 1 wallclock secs ( 2.32 usr + 0.00 sys = 2.32 CPU) @ 215517.24/s (n=50) -- tdk
CR LF
Billy, I do a lot of Perl on an NT box that eventually gets used in both NT and Debian. It was pretty frustrating at first, experiencing your problem. A nice little one-liner that I use after taking a script from NT to a linux system is: perl -w -i -p -e "s/\x0d//g" filename Stephen Neu Internet Development Characterlink.net (630) 323-9800 ext. 235 "What is so difficult for developers to accept sometimes is that there already is a standard, and they didn't write it." --Steve Neu
Re: MySQL Blobs DBI & CGI
At 06:11 AM 4/27/2001, you wrote: >Hi, Hello there. : ) >I have managed to get a blob(a jpeg file) from a local file on the >linux box into the database, but I can't seem to get the thing back >out and onto a webpage! I have scanned numerous lists and books, >but seem to be unable to find any real information on dealing with >blobs. Can anyone point me in the right direction ? > >Thanks very much for you time > >Edd Dawson Well... Are your selects involving blobs failing, or the data getting messed up once it's coming out? Also, you're database is on a Linux machine as stated, but what is your web server on? I think I can give you some advice that isn't totally wrong after the answers to those questions. Thank you for your time, Sean.
Re: Error: Runtime Exception
On Thu, Apr 26, 2001 at 06:43:37PM -0500, Arante, Susan wrote: > This used to be working but after my very adventurous fiasco (deleting > perl5, installing perl6, deleting perl6, installing perl5 - yes i deleted > not uninstalled), it's not working anymore. I'm running perl5 on NT. Given that there *is* no perl6 (yet), I'm guessing you don't really mean that, right? dha -- David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/ however, if people don't like Perl, they don't have to use it. they can stay at the office solving their problems while the Perl Mongers go out and drink. ;)- brian d foy in c.l.p.misc
Re: Error: Runtime Exception
--- "David H. Adler" <[EMAIL PROTECTED]> wrote: > On Thu, Apr 26, 2001 at 06:43:37PM -0500, Arante, Susan wrote: > > This used to be working but after my very adventurous fiasco > > (deleting perl5, installing perl6, deleting perl6, installing perl5 > > - yes i deleted not uninstalled), it's not working anymore. I'm > > running perl5 on NT. > > Given that there *is* no perl6 (yet), I'm guessing you don't really > mean that, right? I colloquial if inaccurate reference 5.6.0. Yes? I'm guilty of it myself. __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Re: Error: Runtime Exception
On Fri, Apr 27, 2001 at 09:25:33AM -0700, Paul wrote: > > --- "David H. Adler" <[EMAIL PROTECTED]> wrote: > > On Thu, Apr 26, 2001 at 06:43:37PM -0500, Arante, Susan wrote: > > > This used to be working but after my very adventurous fiasco > > > (deleting perl5, installing perl6, deleting perl6, installing perl5 > > > - yes i deleted not uninstalled), it's not working anymore. I'm > > > running perl5 on NT. > > > > Given that there *is* no perl6 (yet), I'm guessing you don't really > > mean that, right? > > I colloquial if inaccurate reference 5.6.0. Yes? > I'm guilty of it myself. If it is, I haven't heard it. *shrug* It's also probably not a great practice to propagate... Perl 6 development's confused enough already... :) dha -- David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/ You kids today have it easy. I remember when we had to write programs with an ice pick and index cards. - Lee Sharp
Re: [BPQ] help!! any idea whats wrong with this??
Timothy Kimball ([EMAIL PROTECTED]) wrote: > > : Because someone (and with apologies to all, I don't recall off the top > : of my head who)correctly pointed out to me earlier in this thread that > : using map() here was inefficient. map() builds and returns an array, so > : there's no point in using it in this void context. Aside from that, > : both do the same thing. The postfix for is cleaner. =o) > > I agree that the postfix is cleaner, but when I benchmark these, map > looks faster- though several months ago, map was slower (IIRC). Maybe > something changed in 5.6.0 to make map faster in a null context...? > > Here's the script & output (Perl 5.6.0 on an Ultra 10): Whoa! It was me who noted that the map should be avoided in void context, but trying your benchmark, I had the same results. However, since I did some benchmarks on my own *before* stating that map should not be used, I had some completely different results. I was suspicious, since your results are by far too fast - an U10 is not that much of a big machine, isn't it? ;-) ...hack, hack, hack... Ah, a Heisenbug. There's a problem with your benchmarking: -- snip -- my @lines = qw( ... timethese(500_000,{ "1. map" => 'map { s/a// } @lines', -- snip -- Inside 'timethese', @lines is unknown and thus empty. Looks as if the Benchmark module ignores '$@' after the eval, but I haven't checked for that. But fact is, you're running 500_000 loops on en empty list, and map doesn't need to create any new list at all - well, at least it looks as if map is *pretty* fast on empty lists. There are 2 modifications required in your benchmark: a. make the @list array global, so it's visible inside 'timethese' b. make sure the s/ doesn't truncate the string, so there's still some work to do after 10 test loops. (I did that by replacing s/ with a switching tr...) ( c. as a not really necessary addon I decided to create more random test data (yes, I *am* using nested maps there >:-> ). ) Here's my version of your benchmark: -- snip -- kanku-dai:~$ cat check.pl #!/usr/bin/perl -w use strict; use Benchmark; use vars qw{@lines}; my @chars=('A'..'Z', 'a'..'z', 0 .. 9, ' '); @lines=map { join('', @chars[map { rand @chars } (0 .. 63)]) } (1 .. 10); timethese(500_000,{ "1. map" => 'map { tr/abAB/baBA/ } @lines', "2. foreach" => 'foreach ( @lines ) { tr/abAB/baBA/ }', "3. for" => 'tr/abAB/baBA/ for @lines', }); -- snip -- Here are the new results: -- new -- kanku-dai:~$ perl check.pl Benchmark: timing 50 iterations of 1. map, 2. foreach, 3. for... 1. map: 7 wallclock secs ( 6.95 usr + 0.01 sys = 6.96 CPU) @ 71839.08/s (n=50) 2. foreach: 9 wallclock secs ( 8.38 usr + 0.01 sys = 8.39 CPU) @ 59594.76/s (n=50) 3. for: 9 wallclock secs ( 8.13 usr + 0.01 sys = 8.14 CPU) @ 61425.06/s (n=50) kanku-dai:~$ -- new -- So, it looks as if you're right, map *IS* a bit faster on small data sets, but not in the dimensions that your benchmark suggested. Increasing the amount of data makes that difference go away however. Here's the data for 500 benchmark loops over 10_000 lines of data: -- mod_new -- kanku-dai:~$ perl check.pl Benchmark: timing 500 iterations of 1. map, 2. foreach, 3. for... 1. map: 10 wallclock secs ( 9.71 usr + 0.04 sys = 9.75 CPU) @ 51.28/s (n=500) 2. foreach: 9 wallclock secs ( 9.58 usr + 0.01 sys = 9.59 CPU) @ 52.14/s (n=500) 3. for: 9 wallclock secs ( 9.44 usr + 0.02 sys = 9.46 CPU) @ 52.85/s (n=500) kanku-dai:~$ -- mod_new -- Conclusion: The perlfaq6 information seems outdated, so the only argument against map is the question of style, readability and personal taste - naturally, I stick with my style ;-) Mike -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: [BPQ] help!! any idea whats wrong with this??
: Ah, a Heisenbug. There's a problem with your benchmarking: Yep, you're right. map is slightly slower when it actually has something to do. I stand corrected... again. So the moral of the story is: If you want your code to run really fast, make it do nothing. ;) That's what I love about Perl: been programming with it for 8 years, & still learning. -- tdk
subroutines in .pm
Hello, Does anybody know how to call a subroutine that is in a .pm file from another .pm file.
Beginner's question
All, I am writing a small perl script which is included below. I 've a problem with this line my $prjstream = `cleartool lsstream -in @prjname[1]\@$ucmvob | grep Int` ; It doesn't recognise $ucmvob in this command. But if I replace the variable $ucmvob with the string "/ebppvobstore/vobs/UCMCQ" it works. I am not able to figure out why it doesn't work if I specify the variable. Not that the syntax of this command is "cleartool lsstream -in name@/ebppvobstore/vobs/UCMCQ". #!/usr/local/bin/perl use strict ; my $ucmvob = "/ebppvobstore/vobs/UCMCQ" ; my $PR_NAME = ; my $vobname = `cleartool lsproject -invob $ucmvob | grep $PR_NAME` ; my @prjname = split /\s+/, $vobname ; my $prjstream = `cleartool lsstream -in @prjname[1]\@$ucmvob | grep Int` ; my @Intstream = split /\s+/, $prjstream ; print "@Intstream[1] \n" ; I would appreciate any help on this. Thx Kailash
Re: subroutines in .pm
>Does anybody know how to call a subroutine that is in a .pm file from >another .pm file. Welp, if &subroutine_1 is in Library1.pm, then within Library2.pm, you could do something like: sub subroutine_2 { require "/path/to/Library1.pm"; &subroutine_1; } Morbus Iff .sig on other machine. http://www.disobey.com/ http://www.gamegrene.com/
Re: subroutines in .pm
Morse, Loretta ([EMAIL PROTECTED]) wrote: > > Hello, > > Does anybody know how to call a subroutine that is in a .pm file from > another .pm file. That depends: First you have to load the file via 'require' or 'use' - perldoc them. If your other .pm creates its own namespace, you need to address it as &Module1::test If the .pm has no private namespace, you can use the function just by its name. Here's some sample code: -- check.pl -- #!/usr/bin/perl -w use strict; use Module1; use Module2; &test1; #BROKEN: &test2; &Module2::test2; -- check.pl -- -- Module1.pm -- sub test1 { print "Module1.pm\n"; } 1; -- Module1.pm -- -- Module2.pm -- package Module2; sub test2 { print "Module2.pm\n"; } 1; -- Module2.pm -- Try de-commenting out the '#BROKEN: ' line and see what happens. Of course, things will become more complicated once you learn about the Exporter module - perldoc Exporter -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Beginner's question
> > #!/usr/local/bin/perl > use strict ; > my $ucmvob = "/ebppvobstore/vobs/UCMCQ" ; > my $PR_NAME = ; > my $vobname = `cleartool lsproject -invob $ucmvob | grep $PR_NAME` ; > my @prjname = split /\s+/, $vobname ; > my $prjstream = `cleartool lsstream -in @prjname[1]\@$ucmvob | grep Int` ; Did you mean to write: my $prjstream = `cleartool lsstream -in $prjname[1]\@$ucmvob | grep Int` ; @prjname is the array called 'prjname'. To get the 93rd element of this array, use $prjname[93]. If this wasn't in backtics you'd be tripping use strict. I don't know how perl is trying to interpert it now. > my @Intstream = split /\s+/, $prjstream ; > print "@Intstream[1] \n" ; - Johnathan
Include directory as location of perl script
Hi all, I am executing a perl script from a directory other than the one it is located in. I have a package that the script is using located in the same directory as the script, but the script cannot find this package because the package is not in the include directory. I need a way to include the directory the script is located in as a location for packages WITHOUT passing any parameters to perl or the script itself. I have taken a look at: use lib "PATH" but I am having trouble stripping $0 of the perl script name. Any ideas ? - Craig Moynes Internship Student netCC Development IBM Global Services, Canada Tel: (905) 316-3486 [EMAIL PROTECTED]
Re: Include directory as location of perl script
: but I am having trouble stripping $0 of the perl script name. The standard File::Basename module has a dirname() function that will do that for you. Alternatively, you can say something like this in your perl script: use lib '/path/to/your/module/file.pm'; -- tdk
Clarification - Re: Include directory as location of perl script
I cannot use a fixed library path as the script will be installed in different directories on different systems. the idea is it will be executed as: /home/dbncc/perl/scripts/.pl and the library will also be located in the same directory. - Craig Moynes Internship Student netCC Development IBM Global Services, Canada Tel: (905) 316-3486 [EMAIL PROTECTED] kimball@stsci. edu (Timothy To: [EMAIL PROTECTED] Kimball) cc: Subject: Re: Include directory as location of perl script 04/27/01 04:22 PM Please respond to kimball : but I am having trouble stripping $0 of the perl script name. The standard File::Basename module has a dirname() function that will do that for you. Alternatively, you can say something like this in your perl script: use lib '/path/to/your/module/file.pm'; -- tdk
Re: Clarification - Re: Include directory as location of perl script
Craig Moynes/Markham/IBM ([EMAIL PROTECTED]) wrote: > I cannot use a fixed library path as the script will be installed in > different directories on different systems. > > the idea is it will be executed as: > /home/dbncc/perl/scripts/.pl > > and the library will also be located in the same directory. And the solution has been given to you: > > > kimball@stsci. > > edu (Timothy To: [EMAIL PROTECTED] > > Kimball) cc: > ... > : but I am having trouble stripping $0 of the perl script name. > > The standard File::Basename module has a dirname() function > that will do that for you. ^ there. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
RE: subroutines in .pm
Thanks for the suggestions however I think I need to clarify what I'm trying to do. I am using a WinNT system and I'm running a script that calls a subroutine in file1.pm. Then file1.pm calls a subroutine from file2.pm. The script can't seem to find the subroutine that in is in file2.pm. Neither suggestion has worked so far, any other ideas out there? Thanks. -Original Message- From: Michael Lamertz [mailto:[EMAIL PROTECTED]] Sent: Friday, April 27, 2001 4:06 PM To: Morse, Loretta Cc: '[EMAIL PROTECTED]' Subject: Re: subroutines in .pm Morse, Loretta ([EMAIL PROTECTED]) wrote: > > Hello, > > Does anybody know how to call a subroutine that is in a .pm file from > another .pm file. That depends: First you have to load the file via 'require' or 'use' - perldoc them. If your other .pm creates its own namespace, you need to address it as &Module1::test If the .pm has no private namespace, you can use the function just by its name. Here's some sample code: -- check.pl -- #!/usr/bin/perl -w use strict; use Module1; use Module2; &test1; #BROKEN: &test2; &Module2::test2; -- check.pl -- -- Module1.pm -- sub test1 { print "Module1.pm\n"; } 1; -- Module1.pm -- -- Module2.pm -- package Module2; sub test2 { print "Module2.pm\n"; } 1; -- Module2.pm -- Try de-commenting out the '#BROKEN: ' line and see what happens. Of course, things will become more complicated once you learn about the Exporter module - perldoc Exporter -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
RE: subroutines in .pm
: I am using a WinNT system and I'm running a script that calls : a subroutine in file1.pm. Then file1.pm calls a subroutine : from file2.pm. The script can't seem to find the subroutine : that in is in file2.pm. Does your file1.pm have "use file2" in it? -- tdk
Re: Clarification - Re: Include directory as location of perl script
Camel Book, page 851: One solution for this is to use the standard FindBin module: use FindBin; use lib $FindBin::Bin; This will do just what you want. By the way, to anyone who will listen: Get the Camel Book, "Programming Perl 3rd ed." published by O'Reilly. If you are serious about Perl, get it and read it. You'd be surprised how many of the questions raised here can be solved by a quick glance there. Oh, and just to raise some hell: if you're new to Perl, you may also want to look at Python. I don't know which language I would recomend more... - Johnathan Craig Moynes/Markham/IBM wrote: > I cannot use a fixed library path as the script will be installed in > different directories on different systems. > > the idea is it will be executed as: > /home/dbncc/perl/scripts/.pl > > and the library will also be located in the same directory. > > - > Craig Moynes > Internship Student > netCC Development > IBM Global Services, Canada > Tel: (905) 316-3486 > [EMAIL PROTECTED] > > > > > > kimball@stsci. > > edu (Timothy To: [EMAIL PROTECTED] > > Kimball) cc: > > Subject: Re: Include directory as >location of perl script > 04/27/01 04:22 > > PM > > Please respond > > to kimball > > > > > > > > > > : but I am having trouble stripping $0 of the perl script name. > > The standard File::Basename module has a dirname() function > that will do that for you. > > Alternatively, you can say something like this in your perl script: > > use lib '/path/to/your/module/file.pm'; > > > -- tdk > > > > >
Re: subroutines in .pm
you might consider using the Package pragma: (File1.pm) use strict; Package File1; sub foo { print("Foo!\n"); } (end File1.pm) (File2.pm) use strict; Package File2; use File1; sub foo { print "File1::foo() -> "; File1::foo(); } (end File2.pm) (file main.pl) #!/usr/bin/perl -w use strict; use File1; use File2; sub foo { print "baz\n"; } File1::foo(); File2::foo(); foo(); (end main.pl) Note that the package name was used to specify which function called foo() we were referring to, as there are three, all doing different things. Hope this helps, C.J. > Thanks for the suggestions however I think I need to clarify > what I'm trying to do. > > I am using a WinNT system and I'm running a script that calls > a subroutine in file1.pm. Then file1.pm calls a subroutine > from file2.pm. The script can't seem to find the subroutine > that in is in file2.pm. > > Neither suggestion has worked so far, any other ideas out there? > > Thanks. > > -Original Message- > From: Michael Lamertz [mailto:[EMAIL PROTECTED]] > Sent: Friday, April 27, 2001 4:06 PM > To: Morse, Loretta > Cc: '[EMAIL PROTECTED]' > Subject: Re: subroutines in .pm > > > Morse, Loretta ([EMAIL PROTECTED]) wrote: > >> Hello, >> >> Does anybody know how to call a subroutine that is in a .pm file from >> another .pm file. > > > That depends: > First you have to load the file via 'require' or 'use' - perldoc them. > > If your other .pm creates its own namespace, you need to address it > as &Module1::test > > If the .pm has no private namespace, you can use the function just by > its name. Here's some sample code: > > -- check.pl -- > #!/usr/bin/perl -w > > use strict; > use Module1; > use Module2; > > &test1; > #BROKEN: &test2; > &Module2::test2; > -- check.pl -- > > -- Module1.pm -- > sub test1 { print "Module1.pm\n"; } > 1; > -- Module1.pm -- > > -- Module2.pm -- > package Module2; > sub test2 { print "Module2.pm\n"; } > 1; > -- Module2.pm -- > > Try de-commenting out the '#BROKEN: ' line and see what happens. > > Of course, things will become more complicated once you learn about the > Exporter module - perldoc Exporter >
Re: subroutines in .pm
Morse, Loretta ([EMAIL PROTECTED]) wrote: > Thanks for the suggestions however I think I need to clarify > what I'm trying to do. > > I am using a WinNT system and I'm running a script that calls > a subroutine in file1.pm. Then file1.pm calls a subroutine > from file2.pm. The script can't seem to find the subroutine > that in is in file2.pm. > > Neither suggestion has worked so far, any other ideas out there? Here we go: -- check.pl -- #!/usr/bin/perl -w use strict; use Module1; use Module2; &test_module1; &Module2::test_module2; -- check.pl -- -- Module1.pm -- use Module2; sub called_from_module2 { print "Howdy, mod2\n"; } sub test_module1 { &Module2::called_from_module1; } 1; -- Module1.pm -- -- Module2.pm -- package Module2; use Module1; sub called_from_module1 { print "Howdy, mod1\n"; } sub test_module2 { &main::called_from_module2; } 1; -- Module2.pm -- And here's the output. -- Module2.pm -- kanku-dai:~$ perl check.pl Howdy, mod1 Howdy, mod2 kanku-dai:~$ -- Module2.pm -- Note, that Module1, which doesn't specify a spacename, is put into the 'main' namespace by default, so in the 'Module2' namespace, you have to address it specifically as 'main::function_name'. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Clarification - Re: Include directory as location of perl script
--- Johnathan Kupferer <[EMAIL PROTECTED]> wrote: > . . . > Oh, and just to raise some hell: if you're new to Perl, you may also > want to look at Python. I don't know which language I would recomend > more... I recommend Perl to gearheads and programmers looking for a new tool. For rank beginners, I recommend Python, because I think it's marginally better (cleaner...easier?) for the beginner's mind to grasp. Python does true multithreading and objects, though it hasn't matched Perl in the few performance comparisons I've done. Both are beautiful languages, in my most humble and minimally informed opinion. Python has some great features -- I just prefer Perl personally, because it's more expressive of my personal style. ;o] __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Re: subroutines in .pm
Try throwing this into file2.pm: sub AUTOLOAD { print "What hath god wrought?\n" } And then call: file2->any_function_name; That is if you have a: use file2; AUTOLOAD is a catch all function, method really, but this should work considering how Perl blurs the line between classes and modules. If you don't see the message, you're not loading file2 at all. - Johnathan Timothy Kimball wrote: > : I am using a WinNT system and I'm running a script that calls > : a subroutine in file1.pm. Then file1.pm calls a subroutine > : from file2.pm. The script can't seem to find the subroutine > : that in is in file2.pm. > > Does your file1.pm have "use file2" in it? > > -- tdk > >
Re: Clarification - Re: Include directory as location of perl script
On Fri, 27 Apr 2001, Johnathan Kupferer wrote: > This will do just what you want. By the way, to anyone who will listen: > Get the Camel Book, "Programming Perl 3rd ed." published by O'Reilly. > If you are serious about Perl, get it and read it. You'd be surprised > how many of the questions raised here can be solved by a quick glance there. The Perl Cookbook (O'Reilly Press) is also good for solving many of the problems that seem to come up here. srl -- Shane R. Landrum [EMAIL PROTECTED] we generate our own light to compensate for the lack of light from above -AD GPG public key: http://cs.smith.edu/~slandrum/srl_pgpkey.txt
Re: Clarification - Re: Include directory as location of perl script
Johnathan Kupferer ([EMAIL PROTECTED]) wrote: > Camel Book, page 851: ... > This will do just what you want. By the way, to anyone who will listen: > Get the Camel Book, "Programming Perl 3rd ed." published by O'Reilly. > If you are serious about Perl, get it and read it. You'd be surprised > how many of the questions raised here can be solved by a quick glance there. Yeah, a quick glance... on page 851. LOL! I have both, Ed. 1 and 2. I have really thought about getting v3, but decided that I'd prefere a context-diff agains v2 in favour of the full thing ;-) "Just the deltas maa'm, just the deltas... "perldoc perldelta" "Oh!" > Oh, and just to raise some hell: if you're new to Perl, you may also > want to look at Python. I don't know which language I would recomend > more... Post that on /. if you *really* want some flamefest... :-) -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: subroutines in .pm
--- "Morse, Loretta" <[EMAIL PROTECTED]> wrote: > Hello, > > Does anybody know how to call a subroutine that is in a .pm file from > another .pm file. Given A.pm === package A; sub a { return "a!\n"; } 1; === and B.pm === package B; use A; sub b { print A::a(); } 1; === and C.pl === use B; B::b(); === running C.pl should print "a!\n". Unfortunately, this simple example fails to work for me, though I can make virtually the same call work fine using much more complicated modules I've written. The principle is that you specify the package space. For example, if in your module you use Symbol; then you should be able to generate globs at need with my $glob = Symbol::gensym; "gensym" being a function in the "Symbol" namespace. I've done this in lots of modules. So could somebody point out to me what I'm doing stupid, so no one on this list will copy the part of the above example that I'm doing *wrong*? lol!! __ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
Re: Error: Runtime Exception
Hi At 12:16 PM 4/27/2001 -0400, David H. Adler wrote: >On Thu, Apr 26, 2001 at 06:43:37PM -0500, Arante, Susan wrote: > > This used to be working but after my very adventurous fiasco (deleting > > perl5, installing perl6, deleting perl6, installing perl5 - yes i deleted > > not uninstalled), it's not working anymore. I'm running perl5 on NT. > >Given that there *is* no perl6 (yet), I'm guessing you don't really mean >that, right? Yes I was also surprised about Perl 6, is it out yet ? Regards Joel >dha >-- >David H. Adler - <[EMAIL PROTECTED]> - http://www.panix.com/~dha/ >however, if people don't like Perl, they don't have to use it. they >can stay at the office solving their problems while the Perl Mongers >go out and drink. ;)- brian d foy in c.l.p.misc -- QuantumLink Communications, Bombay, India