Re: How can I find the module version?
On Tue, Jun 10, 2003 at 09:32:53AM -0400 Rick Ressegger wrote: If I want to know what version of a module is already installed on a system, how can I disclose this? Either use Janek's suggestion or ask for the value of $VERSION for the module in question: perl -MSome::Module -e 'warn Some::Module-VERSION' Can multiple versions of a module exist in a library or does one get superceded by another that is installed later? Usually older versions are replaced by newer versions. But see http://search.cpan.org/author/INGY/only/ which allows you to install as many versions of a module as you want. For that see INSTALLING MULTIPLE MODULE VERSIONS in the docs of 'only'. Once you have several versions you can explicitely specify to use a particular version of that module. That's also laid out in the docs. Tassilo -- $_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Find regex in Start/Stop segments
I use a homeboy data base technique to keep info about the scripts I write and other typse of stuff too. Here I'm just dealing with scripts. Its a simple format to enter key information about what a script does. Looks like: # Keywords: SOME WORDS # body # body # DATE # I've written various scripts to search this format in awk and shell. Now trying it in perl. I have several working scripts but wanted to get some ideas from the sharp shooters here how to do this better. My technique seems like it could be streamlined and improved quite a lot. The sample below just handles the basic technique and isn't completed with all tests and etc. Just some basic ones. But really I'm more interested in hearing better ways to accomplish this. The basic task is to locate a formated segment, search its keywords line for regex then print the segment. Also a basic check for misformatted segments. Not too concerned with how the files are aquired but what comes after. ^^ #!/usr/local/bin/perl -w ($myscript = $0) =~ s:^.*/::; $regex = shift; ## Set Keywords start end regex for non script searching (The default) $keyreg = '^# Keywords:'; $keyend = '^# $'; if (!$ARGV[0]) { usage(); exit; } ## Aquire there files in whatever way @files = @ARGV; ## Set a marker to know when we are in a new file $fname_for_line_cnt = ''; for (@files) { chomp; $file = $_; if ($fname_for_line_cnt eq $file) { ## This shouldn't happen print We're reading the same file again .. exiting\n; exit; } else { ## Set lineno to 0 for start of each file $lineno = 0; $fname_for_line_cnt = $file; } if (-f $file) { open(FH,$file) or die Cannot open $file: $!; while (FH) { chomp; $lineno++; $line = $_; if (/$keyreg $regex/) { print $file\n; $hit = TRUE; } if ($hit) { print $lineno $line\n; } if ($hit /$keyend/) { ## We've hit the end of a good segment, print delimiter and null out our vars print -- \n; $hit= ''; $line = ''; } if ($hit /^[^#]/ || $hit eof) { ## If we see this situation it means the format is screwed up ## Notify user of the line number, but null out vars and proceed. print $file:\n INCOMPLETE SEGMENT ENTRY: Line $lineno\n --\n; $hit= ''; $line = ''; } } close(FH); } else { next; } } sub usage { printEOM; Purpose: Search scripts keyword segments (or any file) Usage: \`$myscript REGEX file ... fileN (or glob)' (Where REGEX is a regex to be found in Keyword segment) EOM } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: References...
Thanks Rob, this has been very helpful. I wanted to know why the second form is an abuse of perl. Since I'm new to perl, it is helpful to kn ow what is good programming practise. Tx. H On Tue, 2003-06-10 at 15:39, Rob Dixon wrote: Hamish Whittal wrote: Hi All, I'm still a little confused... What is the difference between %{$config_file-{$key}} Here, $config_file is a hash reference. If you print it it will display something like HASH(0x12345678) The hash it refers to is accessed by the value in $key, so if you had my $config_file = { K = { K2 = 'V2' } }; my $key = 'K'; then $config_file-{$key} would be equal to the anonymous hash { K2 = 'V2' }. This value is then dereferenced again as a hash, so if we have my %hash = %{$config_file-{$key}}; then $config_file-{$key} %hash would be set to %hash = ( K2 = V2 ); %$config_file-{$key} Now this is something altogether different. You've discovered that you can use hash names as references, and this is an abuse of Perl and not to be encouraged! If you had my %config = ( K = { K1 = 'V1' } ); my $config_file = \%config; then %$config_file is the same as %config, so you can access the element with $config{K} or $config_file-{K} What the book doesn't tell you, though, is that Perl will let you treat the hash name as a reference like this %config-{K} which is the same as %$config_file-{K} So you've dereferenced $config_file and then used it as a reference, so achieving nothing. To summarize: %$config_file-{$key} is the same as $config_file-{$key} and so is the same as the first case, %{$config_file-{$key}} without the additional level of dereferencing. But, as I said, don't use the second case! Cheers, Rob -- You are not defined by what loves you, but what you love - Nicholas Cage (Adaptation, 2003) --- Hamish Whittal QED Technologies cc +27 82 803 5533 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Find regex in Start/Stop segments
On Tue, Jun 10, 2003 at 11:49:25PM -0700 Harry Putnam wrote: I use a homeboy data base technique to keep info about the scripts I write and other typse of stuff too. Here I'm just dealing with scripts. Its a simple format to enter key information about what a script does. Looks like: # Keywords: SOME WORDS # body # body # DATE # I've written various scripts to search this format in awk and shell. Now trying it in perl. I have several working scripts but wanted to get some ideas from the sharp shooters here how to do this better. My technique seems like it could be streamlined and improved quite a lot. Yes, it's a little wordy considering it's Perl. The sample below just handles the basic technique and isn't completed with all tests and etc. Just some basic ones. But really I'm more interested in hearing better ways to accomplish this. The basic task is to locate a formated segment, search its keywords line for regex then print the segment. Also a basic check for misformatted segments. Not too concerned with how the files are aquired but what comes after. ^^ #!/usr/local/bin/perl -w ($myscript = $0) =~ s:^.*/::; You are allowed to manipulate $0, too. The new value of $0 is the one that is eventually showing up in your process-table (unless you are using Perl5.8.0 where this does not work due to a bug). $regex = shift; ## Set Keywords start end regex for non script searching (The default) $keyreg = '^# Keywords:'; $keyend = '^# $'; if (!$ARGV[0]) { usage(); exit; } ## Aquire there files in whatever way @files = @ARGV; ## Set a marker to know when we are in a new file $fname_for_line_cnt = ''; for (@files) { chomp; I don't think that the entries in @ARGV contain newlines at the end. Actually I know they don't. :-) $file = $_; if ($fname_for_line_cnt eq $file) { There is no reason to put those variables into quotes. ## This shouldn't happen print We're reading the same file again .. exiting\n; exit; That is better solved using a hash. Fill all the files into a hash (as keys) and iterate over the keys. That way, it's guaranteed you only inspect each file once. } else { ## Set lineno to 0 for start of each file $lineno = 0; $fname_for_line_cnt = $file; } if (-f $file) { open(FH,$file) or die Cannot open $file: $!; while (FH) { chomp; $lineno++; You don't have to keep track of the line numbers yourself. Perl offers the special variable $. for that. $line = $_; if (/$keyreg $regex/) { print $file\n; $hit = TRUE; } if ($hit) { print $lineno $line\n; } if ($hit /$keyend/) { ## We've hit the end of a good segment, print delimiter and null ## out our vars print -- \n; $hit= ''; $line = ''; } if ($hit /^[^#]/ || $hit eof) { ## If we see this situation it means the format is screwed up ## Notify user of the line number, but null out vars and proceed. print $file:\n INCOMPLETE SEGMENT ENTRY: Line $lineno\n --\n; $hit= ''; $line = ''; } } close(FH); } else { next; } } sub usage { printEOM; Purpose: Search scripts keyword segments (or any file) Usage: \`$myscript REGEX file ... fileN (or glob)' (Where REGEX is a regex to be found in Keyword segment) EOM } I'd probably write it like that: #!/usr/local/bin/perl -w use strict; $0 =~ s:.*/::; my $regex = shift; $regex = qr/^# Keywords: $regex/; # could improve performance a little my %files; @files{ @ARGV } = (); # a hash-slice: see 'perldoc perldata' usage(), exit if ! @ARGV; for my $file (keys %files) { next if ! -f $file; open FILE, , $file or die Error opening $file: $!; my $hit; while (FILE) { chomp; $hit++ if /$regex/o;# start of record print $. $_\n if $hit;# $. is the line number $hit-- if /^# $/; # end of record print $file:\n\tINCOMPLETE SEGMENT ENTRY: Line $l.\n--\n and $hit-- if $hit !/^#/ or $hit eof; } } sub usage { ... } I didn't test it but it should produce the same result as your script and doing it considerably more quickly. Please substract any possible syntax errors or logical flaws from the script before running it. ;-) Tassilo -- $_=q#,}])!JAPH!qq(tsuJ[{@tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?=sub).+q#q!'qq.\t$.'!#+sexisexiixesixeseg;y~\n~~;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
regexp
Hi, i've got a problem with regexp, i have a multiline string like this is a multi line string and i want to do a regexp that replaces everything that is NOT a,b,c or d with \s, except \n of course. i got something like $string =~ s/![abcd]//g; but that doesn't work, maybe because it recognizes ! not as negation but as character... so how to do it ? thanks Jaschar Otto -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
Jaschar Otto wrote at Wed, 11 Jun 2003 11:53:11 +0200: i've got a problem with regexp, i have a multiline string like this is a multi line string and i want to do a regexp that replaces everything that is NOT a,b,c or d with \s, except \n of course. \s is not one character, it stands usually for a whole character class! Do you mean an empty string () or just a blank ( ) instead? i got something like $string =~ s/![abcd]//g; character class negation works with [^...], in your case it would be $string =~ s/[^abcd]//g; but that doesn't work, maybe because it recognizes ! not as negation but as character... so how to do it ? Please read also perldoc perlre for details. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
Hi \s is not one character, it stands usually for a whole character class! Do you mean an empty string () or just a blank ( ) instead? i ment a blank ( ). character class negation works with [^...], in your case it would be $string =~ s/[^abcd]//g; Thanks a lot, that worked perfect, maybe i was too blind but i couldn't find this character calss negation in perlre when i searched last time before your post :-) anyways, thanks again -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Global config file....this time defining modules to use...
Hi All, I have a module OraMod.pm that exports some subroutines I also have Common.pm which sets up a whole host of environment variables for use throughout all the modules that I have created. What I now want to do is, instead of placing the use OraMod qw(sub1, sub2, sub3) at the top of all the modules that require it, I want to place it in the Common.pm module too. So I tried: use base 'Exporter'; use OraMod qw(sub1, sub2, sub3); our @EXPORT = qw/$CONFIGDIR $RUNFILES $DefaultPollInterval $DefaultPollYN $DefaultCommunity/; $CONFIGDIR = '/export/home/whittalh/vodanam_update'; $RUNFILES = '/tmp/run'; $DefaultPollInterval = 24; $DefaultPollYN = 'Y'; $DefaultCommunity = 'public'; 1; And at the top of OraMod.pm use Exporter; @ISA = ('Exporter'); @EXPORT_OK = qw(sub1 sub2 sub3); But alas, I still need to explicitly state the OraMod::sub1(params..) in the modules that use the sub1. Any clew to what I am doing wrong. Tx. H -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
File::Copy - Additional Parameters?
Hi all, Anyone know if the perl module File::Copy can handle date checks? Or whether there is another module that only deals with copying files that are newer than the ones they are over-writing? Similar to the Xcopy /D: command [I don't want to use a batch file at the moment in case someone wants to know why I'm not using Xcopy] Regards Ben __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: DNS Lookup
Airman wrote: Does anyone know how to reference different DNS servers when using gethostbyname. I want to check up to three different nameserver for consistency checking. Use Net::DNS module instead. gethostbyname() isn't really designed for that kind of thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
printing a hash
I have a hash called fouls. Within that hash, there are other hashes called offensive, personal, and shooting. The keys to those hashes are names, like Smith, Rodriguez, and Chan. and the values to those names are numbers. I think if I wanted to access the number of offensive fouls Chan committed, the syntax would be this: $fouls{$offensive}{$Chan}; Is that right? Assuming it is, and I have a file that is collecting the lines that indicate fouls, then of those, separating the ones that indicate offensive, personal and shooting, and then of those the ones that indicate Smith, Chan and Rodriguez and then increment each instance. If my backreference variable $3 was storing on each pass in the while loop the type of foul (offensive, personal or shooting) and $1 was storing the name (Chan, Rodrigues or Smith) how would I print the %fouls hash out so that the output would be grouped by type of foul? Here is an example of the output I'd like to see? Offensive fouls: Chan: 3 Rodriguez: 1 Smith: 1 Personal fouls: Chan: 1 Rodriguez: 4 Smith: 1 Shooting fouls: Chan: 1 Rodriguez: 1 Smith: 2 would I nest foreach loops? If so, I'm still not sure how I'd do that. Thanks in advance. -stu __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: pattern matching
Chern Jian Leaw wrote: From: Rob Dixon Chern Jian Leaw wrote: I have a text file below which is simply an output from the UNIX utility rpcinfo: 181 udp 55734 walld program 18 version 1 ready and waiting 1073741 udp 64018 rpcinfo: RPC: Timed out 181 tcp 55684 sprayd program 18 version 1 sleeping In the attached script, I'm extracting the lines from the file which does NOT match the string ready and waiting. For those lines from the rpcinfo output which did not match ready and waiting string, an e-mail would be sent out to some respective sys admin. In the script, I've obtained the attributes i.e. the program no, version, protocol, port, and response via pattern matching: $waiting[$lines]=~m/^(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(.*)$/; where $waiting[lines] contains all lines not matching the string ready and waiting. However, for the case of the response having the pattern: rpcinfo:RPC:Timed Out I would have to split this pattern with the : as the delimiter in order to obtain the output format as below, in the e-mail content: PROG NO VERSION PROTOCOL PORT SERVICE RESPONSE 1073741udp 64018 rpcinfo Timed Out 181udp 55684 sprayd sleeping I was wondering if there are ways which I can do so in just a single pattern matching arithmetic to obtain the attributes to correspond with the output format above? Any other better/more efficient ideas on performing such pattern match would indeed be appreciated. Well I can offer you the code below, which splits each line on one or more whitespace characters, optionally preceded by a space. But I can't see a way of describing how much of the end of the text you want as the 'response'. There's nothing to differentiate taking the last word of 'program 18 version 1 sleeping' to say 'sleeping', as opposed to the last two words of 'RPC: Timed out' to say 'Timed out'. Can you specify what you need a little more precisely, and show us a better example of the input? while (DATA) { chomp; next if /ready and waiting/; my @details = split /:?\s+/, $_, 7; shift @details; $ = ' / '; print @details\n; } __DATA__ 181 udp 55734 walld program 18 version 1 ready and waiting 1073741 udp 64018 rpcinfo: RPC: Timed out 181 tcp 55684 sprayd program 18 version 1 sleeping OUTPUT 107374 / 1 / udp / 64018 / rpcinfo / RPC: Timed out 18 / 1 / tcp / 55684 / sprayd / program 18 version 1 sleeping From the output generated below, I would like to obtain the string from RPC: Timed out onwards. This string corresponds to the response attribute. Another example of the response attribute is the program 18 version 1 sleeping. 107374 / 1 / udp / 64018 / rpcinfo / RPC: Timed out 18 / 1 / tcp / 55684 / sprayd / program 18 version 1 sleeping Hence I would like to know if there is a more efficient way of performing a pattern match which also includes delimiters like the : and spaces? Since you pointed out that There's nothing to differentiate taking the last word of 'program 18 version 1 sleeping' to say 'sleeping', as opposed to the last two words of 'RPC: Timed out' to say 'Timed out'., I would just like to obtain the service names rpcinfo and sprayd and the response attribute i.e. RPC: Timed out (ignoring the : before RPC i.e. :RPC) and program 18 version 1 sleeping. What you want is already there if you look at my code. I've writtten it differently from your program in that I'm using 'split' instead of regex captures. I missed the attachment on your original post. Let's take a look at that. use strict; # always use warnings; # usually (or people won't be in a hurry to answer your questions!) use Cwd; $currDir=cwd; $file=$currDir./rpc.txt; If you're always opening a file in the current directory you don't need the 'Cwd' module. Just my $file = 'rpc.txt'; will do. `/etc/rpcping |grep -v RPC|grep -v program $file`; print \$file = $file \n; @waiting = `grep -v ready and waiting $file`; It's not a good idea to shell out to Unix utilities to do something that Perl can do easily. But since this command line looks wrong to me anyway I'm leaving it as it is. (I think it runs 'rpcping' and writes to $file the lines which contain neither 'RPC' nor 'program'. But that's not consistent with the file contents that you posted.) print Processing invalid process now ...\n; open (MAIL, |/usr/bin/mailx -s 'RPCPING OUTPUT' cleaw); Again, using an external utility isn't the way to build and send email in Perl. print MAIL PROG NO\t\t\VER\t\t\PROTO\t\t\PORT\t\t\RESPONSE\t\t\t\n; for ($lines=0;$lines@waiting; $lines++) { print \$waiting[$lines]= $waiting[$lines]\n; This is C code
Re: printing a hash
Hi Stuart. This project of yours is coming along nicely! Stuart White wrote: I have a hash called fouls. Within that hash, there are other hashes called offensive, personal, and shooting. The keys to those hashes are names, like Smith, Rodriguez, and Chan. and the values to those names are numbers. I think if I wanted to access the number of offensive fouls Chan committed, the syntax would be this: $fouls{$offensive}{$Chan}; Is that right? Yes, as long as you have a named hash %fouls. If it is an anonymous hash referenced by scalar $fouls, then you want $fouls-{$offensive}{$Chan}; Assuming it is, and I have a file that is collecting the lines that indicate fouls, then of those, separating the ones that indicate offensive, personal and shooting, and then of those the ones that indicate Smith, Chan and Rodriguez and then increment each instance. If my backreference variable $3 was storing on each pass in the while loop the type of foul (offensive, personal or shooting) and $1 was storing the name (Chan, Rodrigues or Smith) OK lets stop there. I don't think you want to do it like that. If, as you say, you have foul type in $3 and player name in $1 then you want to accumulate them like this $fouls{$3}{$1}++; which, if $1 eq 'Chan' and $3 eq 'offensive' would increment the element $fouls{offensive}{Chan} Which is a lot nicer as you don't then have to declare a scalar variable for every possible player. Be careful about upper and lower case characters though: as far as Perl's concerned 'Chan' and 'chan' are two different players! How would I print the %fouls hash out so that the output would be grouped by type of foul? Here is an example of the output I'd like to see. Offensive fouls: Chan: 3 Rodriguez: 1 Smith: 1 Personal fouls: Chan: 1 Rodriguez: 4 Smith: 1 Shooting fouls: Chan: 1 Rodriguez: 1 Smith: 2 would I nest foreach loops? If so, I'm still not sure how I'd do that. You'd have to look at the three subhashes separately. Try this foreach $type ( qw/Offensive Personal Shooting/ ) { printf %s fouls\n, $type; my $rank = $fouls{lc $type}; foreach my $player (keys %$rank) { printf %s: %d\n, $player, $rank-{$player}; } } I hope that's clear. Note that I've pulled out a reference to the second-level hash in $rank to simplify the inner loop. I've also lower-cased the values for $type to make sure that it matches the hash key. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
very beginner
Could someone direct me to the correct module to use for monitoring an Internet connection? I just want to see the IP addresses of the machines trying to get into my PC. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
On Wednesday, June 11, 2003, at 05:14 AM, Jaschar Otto wrote: $string =~ s/[^abcd]//g; Thanks a lot, that worked perfect, Transliterate is probably a better choice for this kind of thing. It's certainly more efficient. You would use it like this: $string =~ tr/abcd/ /c; James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: very beginner
Steps: 1. Install Windump http://windump.polito.it/ 2. Watch logfile, or write perl script to parse log file. Luke -Original Message- From: DiGregorio, Dave [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 7:04 AM To: Bakken, Luke Subject: RE: very beginner Win ME -Original Message- From: Bakken, Luke [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 10:04 AM To: DiGregorio, Dave Subject: RE: very beginner What operating system are you using? -Original Message- From: DiGregorio, Dave [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 6:52 AM To: [EMAIL PROTECTED] Subject: very beginner Could someone direct me to the correct module to use for monitoring an Internet connection? I just want to see the IP addresses of the machines trying to get into my PC. -- 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: regexp
On Wednesday, June 11, 2003, at 05:14 AM, Jaschar Otto wrote: $string =~ s/[^abcd]//g; Thanks a lot, that worked perfect, Transliterate is probably a better choice for this kind of thing. It's certainly more efficient. You would use it like this: Just curious, how is it more efficient? Can you use anchors in tr ? because in the =~ example above it would match a string: abcd foo monkey But not monkey abcd foo While the tr version would match both. Just wondering Dan $string =~ tr/abcd/ /c; James -- 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: Global config file....this time defining modules to use...
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Hamish Whittal) writes: Hi All, I have a module OraMod.pm that exports some subroutines I also have Common.pm which sets up a whole host of environment variables for use throughout all the modules that I have created. What I now want to do is, instead of placing the use OraMod qw(sub1, sub2, sub3) at the top of all the modules that require it, I want to place it in the Common.pm module too. So I tried: use base 'Exporter'; use OraMod qw(sub1, sub2, sub3); our @EXPORT = qw/$CONFIGDIR $RUNFILES $DefaultPollInterval $DefaultPollYN $DefaultCommunity/; $CONFIGDIR = '/export/home/whittalh/vodanam_update'; $RUNFILES = '/tmp/run'; $DefaultPollInterval = 24; $DefaultPollYN = 'Y'; $DefaultCommunity = 'public'; 1; And at the top of OraMod.pm use Exporter; @ISA = ('Exporter'); @EXPORT_OK = qw(sub1 sub2 sub3); But alas, I still need to explicitly state the OraMod::sub1(params..) in the modules that use the sub1. Any clew to what I am doing wrong. The Exporter only exports to the caller by default. So sub1() can be called without qualification in OraMod.pm but not in OraMod's caller unless you export it from there as well. This should make it clear: $ cat Foo.pm package Foo; use base Exporter; use Bar; our @EXPORT = qw(bar); 1; $ cat Bar.pm package Bar; use base Exporter; our @EXPORT = qw(bar); sub bar { print Bar\n } 1; $ cat foo #!/usr/bin/perl use strict; use warnings; use Foo; bar(); $ ./foo Bar -- Peter Scott http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
On Wednesday, June 11, 2003, at 09:21 AM, Dan Muey wrote: On Wednesday, June 11, 2003, at 05:14 AM, Jaschar Otto wrote: $string =~ s/[^abcd]//g; Thanks a lot, that worked perfect, Transliterate is probably a better choice for this kind of thing. It's certainly more efficient. You would use it like this: Just curious, how is it more efficient? Transliterate is faster because it doesn't have to fire up the Regular Expression engine. Can you use anchors in tr ? No, but there were no anchors used in the above search. The problem was to replace all non qw(a b c d) characters with a space. That's a textbook perfect definition of what Transliterate does. because in the =~ example above it would match a string: abcd foo monkey But not monkey abcd foo While the tr version would match both. Na, you're confusing your ^ characters. ;) What you said is written: s/^abcd/ /; The search above was: s/[^abcd]/ /; It means any non qw(a b c d) character. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
Dan Muey wrote: On Wednesday, June 11, 2003, at 05:14 AM, Jaschar Otto wrote: $string =~ s/[^abcd]//g; Thanks a lot, that worked perfect, Transliterate is probably a better choice for this kind of thing. It's certainly more efficient. You would use it like this: Just curious, how is it more efficient? Because it doesn't involve any pattern matching. The translation is a straightforward byte for byte mapping. Can you use anchors in tr ? You can't use regexes at all with tr//. because in the =~ example above it would match a string: abcd foo monkey The caret at the start of a character class negates the sense of the class, so /[abcd]/ matches a character which is any one of the four letters 'a', 'b', 'c' or 'd'. /[^abcd]/ will match any single character except these four. In the expression ($string = 'abcd foo monkey') =~ s/[^abcd]/ /g; the regex matches four times - once for each of the first four characters. But not monkey abcd foo ($string = 'monkey abcd foo') =~ s/[^abcd]/ /g; also matches four times - starting at offset 7 within the string. While the tr version would match both. Both have the same effect as $string =~ tr/a-d/ /; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
--- Rob Dixon [EMAIL PROTECTED] wrote: Hi Stuart. This project of yours is coming along nicely! Thanks, I'm getting some help from a tutor and you all on this list, which is helping me move along much faster than I could have done by myself. Stuart White wrote: I have a hash called fouls. Within that hash, there are other hashes called offensive, personal, and shooting. The keys to those hashes are names, like Smith, Rodriguez, and Chan. and the values to those names are numbers. I think if I wanted to access the number of offensive fouls Chan committed, the syntax would be this: $fouls{$offensive}{$Chan}; Is that right? Yes, as long as you have a named hash %fouls. If it is an anonymous hash referenced by scalar $fouls, then you want $fouls-{$offensive}{$Chan}; Whew, good thing for my ego that I got that one right. I do have a hash named %fouls. No references yet, that's next. Assuming it is, and I have a file that is collecting the lines that indicate fouls, then of those, separating the ones that indicate offensive, personal and shooting, and then of those the ones that indicate Smith, Chan and Rodriguez and then increment each instance. If my backreference variable $3 was storing on each pass in the while loop the type of foul (offensive, personal or shooting) and $1 was storing the name (Chan, Rodrigues or Smith) OK lets stop there. I don't think you want to do it like that. If, as you say, you have foul type in $3 and player name in $1 then you want to accumulate them like this $fouls{$3}{$1}++; Yes, I'd want to use the backreferenced variables within the loop, the name of the foul and the name of the player was just for illustration. I guess I didn't clear that up. My mistake. Strangely enough, I still don't quite understand completely what that's doing, but what I'm hoping that syntax does is distinguish each player name and each type of foul and group the kinds of fouls with each player that committed them, and the count. I took a bit of a leap from this earlier example: $fouls{$1}++; Which kept track of the number of fouls for each player, but grouped all fouls together. which, if $1 eq 'Chan' and $3 eq 'offensive' would increment the element $fouls{offensive}{Chan} Which is a lot nicer as you don't then have to declare a scalar variable for every possible player. Be careful about upper and lower case characters though: as far as Perl's concerned 'Chan' and 'chan' are two different players! Yup, the nomenclature for the names, fouls and everything with the log is standardized, so I won't run into 'chan' and 'Chan.' thanks for the heads up though. How would I print the %fouls hash out so that the output would be grouped by type of foul? Here is an example of the output I'd like to see. Offensive fouls: Chan: 3 Rodriguez: 1 Smith: 1 Personal fouls: Chan: 1 Rodriguez: 4 Smith: 1 Shooting fouls: Chan: 1 Rodriguez: 1 Smith: 2 would I nest foreach loops? If so, I'm still not sure how I'd do that. You'd have to look at the three subhashes separately. Try this foreach $type ( qw/Offensive Personal Shooting/ ) { printf %s fouls\n, $type; my $rank = $fouls{lc $type}; foreach my $player (keys %$rank) { printf %s: %d\n, $player, $rank-{$player}; } } Hmm, it's not. I'm getting confused by the variable names and what each represent since the $1 or the $3 isn't in there. Also, can I do it without the reference? Thanks for the help. -stu I hope that's clear. Note that I've pulled out a reference to the second-level hash in $rank to simplify the inner loop. I've also lower-cased the values for $type to make sure that it matches the hash key. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regexp
The caret at the start of a character class negates the sense of the class, so /[abcd]/ matches a character which is any one of the four letters 'a', 'b', 'c' or 'd'. /[^abcd]/ will match any single character except these four. In the expression Ooo yeah the brackets change the carrot. What a monkey I am. Thanks Rob for the clarification once again. Dan ($string = 'abcd foo monkey') =~ s/[^abcd]/ /g; the regex matches four times - once for each of the first four characters. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
Stuart White wrote: --- Rob Dixon [EMAIL PROTECTED] wrote: Stuart White wrote: I have a hash called fouls. Within that hash, there are other hashes called offensive, personal, and shooting. The keys to those hashes are names, like Smith, Rodriguez, and Chan. and the values to those names are numbers. I think if I wanted to access the number of offensive fouls Chan committed, the syntax would be this: $fouls{$offensive}{$Chan}; Is that right? Yes, as long as you have a named hash %fouls. If it is an anonymous hash referenced by scalar $fouls, then you want $fouls-{$offensive}{$Chan}; Whew, good thing for my ego that I got that one right. I do have a hash named %fouls. No references yet, that's next. Assuming it is, and I have a file that is collecting the lines that indicate fouls, then of those, separating the ones that indicate offensive, personal and shooting, and then of those the ones that indicate Smith, Chan and Rodriguez and then increment each instance. If my backreference variable $3 was storing on each pass in the while loop the type of foul (offensive, personal or shooting) and $1 was storing the name (Chan, Rodrigues or Smith) OK lets stop there. I don't think you want to do it like that. If, as you say, you have foul type in $3 and player name in $1 then you want to accumulate them like this $fouls{$3}{$1}++; Yes, I'd want to use the backreferenced variables within the loop, the name of the foul and the name of the player was just for illustration. I guess I didn't clear that up. My mistake. Strangely enough, I still don't quite understand completely what that's doing, but what I'm hoping that syntax does is distinguish each player name and each type of foul and group the kinds of fouls with each player that committed them, and the count. Conceptually, what you have is a tree. There are three branches from the root, one for each foul type, and each of these is split into a further three branches, one for each player. Internally what you have is a hash, %fouls, which relates foul types (as the hash keys) to hash references (as the values). Each of these references refer to a hash which relates player names (as the keys) to foul count (as the values). It may be helpful to do this use Data::Dumper; print Dumper \%fouls; which will output Perl code to reconstruct the hash contents. It provides a useful visual representation of the hash you've built. I took a bit of a leap from this earlier example: $fouls{$1}++; Which kept track of the number of fouls for each player, but grouped all fouls together. which, if $1 eq 'Chan' and $3 eq 'offensive' would increment the element $fouls{offensive}{Chan} Which is a lot nicer as you don't then have to declare a scalar variable for every possible player. Be careful about upper and lower case characters though: as far as Perl's concerned 'Chan' and 'chan' are two different players! Yup, the nomenclature for the names, fouls and everything with the log is standardized, so I won't run into 'chan' and 'Chan.' thanks for the heads up though. How would I print the %fouls hash out so that the output would be grouped by type of foul? Here is an example of the output I'd like to see. Offensive fouls: Chan: 3 Rodriguez: 1 Smith: 1 Personal fouls: Chan: 1 Rodriguez: 4 Smith: 1 Shooting fouls: Chan: 1 Rodriguez: 1 Smith: 2 would I nest foreach loops? If so, I'm still not sure how I'd do that. You'd have to look at the three subhashes separately. Try this foreach $type ( qw/Offensive Personal Shooting/ ) { printf %s fouls\n, $type; my $rank = $fouls{lc $type}; foreach my $player (keys %$rank) { printf %s: %d\n, $player, $rank-{$player}; } } Hmm, it's not. Not what? :) I'm getting confused by the variable names and what each represent since the $1 or the $3 isn't in there. Scalar $type holds the foul type. The same as $3 on input. Scalar $player holds the player name. The same as $1 on input. Also, can I do it without the reference? You can do it without the hash reference but it looks more confusing that way. You can't get around the fact that the level 2 hashes are anonymous ones so you need to understand references. foreach my $type ( qw/Offensive Personal Shooting/ ) { printf %s fouls\n, $type; foreach my $player ( keys %{$fouls{$type}} ) { printf %s: %d\n, $player, $fouls{$type}{$player}; } } Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File::Copy - Additional Parameters?
Hi Ben Ben Crane wrote: Anyone know if the perl module File::Copy can handle date checks? Or whether there is another module that only deals with copying files that are newer than the ones they are over-writing? Similar to the Xcopy /D: command [I don't want to use a batch file at the moment in case someone wants to know why I'm not using Xcopy] File::Copy won't handle dates directly. Either use 'stat' to check the date of each file before it is copied or use File::NCopy and write your own 'file_check' routine. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: File::Copy - Additional Parameters?
You could always use stat() on the files to decide which ones you want to copy... -Original Message- From: Ben Crane [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 4:31 AM To: [EMAIL PROTECTED] Subject: File::Copy - Additional Parameters? Hi all, Anyone know if the perl module File::Copy can handle date checks? Or whether there is another module that only deals with copying files that are newer than the ones they are over-writing? Similar to the Xcopy /D: command [I don't want to use a batch file at the moment in case someone wants to know why I'm not using Xcopy] Regards Ben __ Do you Yahoo!? Yahoo! Calendar - Free online calendar with sync to Outlook(TM). http://calendar.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: Find regex in Start/Stop segments
Tassilo von Parseval [EMAIL PROTECTED] writes: You don't have to keep track of the line numbers yourself. Perl offers the special variable $. for that. An awkism I guess, hold over from awk use. Thanks for the tips. I'd probably write it like that: Quite a lot shorter... and to the point. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Changing UID/GID
Hi everybody! Could You pease point me where I can get answers following questions: 1. How can I now the UID of the user who started perl-script? 2. How can I change UID/GID the script is running under. I need to start script with root privilegies and when drop them to apache.apache. Thanks in advance for help. Best regards Sergios -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
snip Conceptually, what you have is a tree. There are three branches from the root, one for each foul type, and each of these is split into a further three branches, one for each player. Like this: --Rodriguez{numFouls} --offensive--Chan{numFouls} --Smith{numFouls} --Rodriguez{numFouls} fouls--personal--Chan{numFouls} --Smith{numFouls} --Rodriguez{numFouls} --shooting--Chan{numFouls} --Smith{numFouls} That's what I conceptually see, and what I think it should be. Internally what you have is a hash, %fouls, which relates foul types (as the hash keys) to hash references (as the values). Each of these references refer to a hash which relates player names (as the keys) to foul count (as the values). internally, that looks like this, right? $fouls{offensive}{Chan} then substitute the foultype and the player name for the 8 other options. It may be helpful to do this use Data::Dumper; print Dumper \%fouls; the call to print is after I've written the hash, right? and the use Data::Dumper; is just like typing use strict; right? I don't have to do anything else with that I suppose? which will output Perl code to reconstruct the hash contents. It provides a useful visual representation of the hash you've built. I took a bit of a leap from this earlier example: $fouls{$1}++; Which kept track of the number of fouls for each player, but grouped all fouls together. which, if $1 eq 'Chan' and $3 eq 'offensive' would increment the element $fouls{offensive}{Chan} I actually did something like this when I had 1-d hashes, but six of them, one for every different foul(for simplicity's sake, I've just written names of 3 diff kinds of fouls), but then I thought I'd have to write a bunch of lines like you wrote for the 2-d hash, which I thought would be cumbersome, since there are plenty of different names. I had something like: if ($3 eq 'Offensive') { $offensive{$1}++; } That's when he suggested that I didn't have to match $3 or $1 to anything, and so sent me on a chase to figure out how. That's how I came up with the thought that I'm not matching the name in the example above ($1) so perhaps I could write a line like so: $fouls{$3}{$1}++; and that would do the same thing if wrote: if ($1 eq 'Chan' and $3 eq 'offensive') { $fouls{$3}{$1}++; } or something like that. So this is what I'd like to do, count fouls without using string comparison operators. Which is a lot nicer as you don't then have to declare a scalar variable for every possible player. Be careful about upper and lower case characters though: as far as Perl's concerned 'Chan' and 'chan' are two different players! Yup, the nomenclature for the names, fouls and everything with the log is standardized, so I won't run into 'chan' and 'Chan.' thanks for the heads up though. How would I print the %fouls hash out so that the output would be grouped by type of foul? Here is an example of the output I'd like to see. Offensive fouls: Chan: 3 Rodriguez: 1 Smith: 1 Personal fouls: Chan: 1 Rodriguez: 4 Smith: 1 Shooting fouls: Chan: 1 Rodriguez: 1 Smith: 2 would I nest foreach loops? If so, I'm still not sure how I'd do that. You'd have to look at the three subhashes separately. Try this foreach $type ( qw/Offensive Personal Shooting/ ) { printf %s fouls\n, $type; my $rank = $fouls{lc $type}; foreach my $player (keys %$rank) { printf %s: %d\n, $player, $rank-{$player}; } } Hmm, it's not. Not what? :) My mistake, I meant to write that below, it wasn't clear. I'm getting confused by the variable names and what each represent since the $1 or the $3 isn't in there. Scalar $type holds the foul type. The same as $3 on input. Scalar $player holds the player name. The same as $1 on input. Yes, but was supposed to assume that further up in the code I would have assigned $1 to $player, and $3 to $type? That's where a lot of my confusion came from. Then, what does $rank refer to? Wait, it looks like it is assigned to $fouls{$type} so then $rank would have a key of foultype, and a value of player name which is also a key and would have a value of the number of fouls? Is that it? and I'm not familiar with this syntax: %$rank Also, can I do it without the reference? You can do it without the hash reference but it looks more confusing that way. You can't get around the fact that the level 2 hashes are anonymous ones so you need to understand references. I asked because I'm still moving in baby steps here. :) References are next. Before this would work, I'd have to assingn $3 to $type and $1 to $player, right? foreach my $type ( qw/Offensive Personal
Re: Changing UID/GID
On Wed, 11 Jun 2003, tsg wrote: Hi everybody! Could You pease point me where I can get answers following questions: 1. How can I now the UID of the user who started perl-script? Try $ (or $UID or $REAL_USER_ID with use English) for the real user id. Try $ or $EUID or $EFFECTIVE_USER_ID with use English for the effective user ID. 2. How can I change UID/GID the script is running under. I need to start script with root privilegies and when drop them to apache.apache. perldoc POSIX. (and search for setuid). Regards, Shlomi Fish Thanks in advance for help. Best regards Sergios -- Shlomi Fish[EMAIL PROTECTED] Home Page: http://t2.technion.ac.il/~shlomif/ An apple a day will keep a doctor away. Two apples a day will keep two doctors away. Falk Fish -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
Stuart White wrote: Conceptually, what you have is a tree. There are three branches from the root, one for each foul type, and each of these is split into a further three branches, one for each player. Like this: --Rodriguez{numFouls} --offensive--Chan{numFouls} --Smith{numFouls} --Rodriguez{numFouls} fouls--personal--Chan{numFouls} --Smith{numFouls} --Rodriguez{numFouls} --shooting--Chan{numFouls} --Smith{numFouls} That's what I conceptually see, and what I think it should be. That's about it. Your notation isn't consistent but I shouldn't worry about that. Internally what you have is a hash, %fouls, which relates foul types (as the hash keys) to hash references (as the values). Each of these references refer to a hash which relates player names (as the keys) to foul count (as the values). internally, that looks like this, right? $fouls{offensive}{Chan} then substitute the foultype and the player name for the 8 other options. Well, that's just the syntax for extracting a single count from the structure. You need to understand that $fouls{offensive} is a hash reference. That's why I suggested Dumper. It may be helpful to do this use Data::Dumper; print Dumper \%fouls; the call to print is after I've written the hash, right? and the use Data::Dumper; is just like typing use strict; right? I don't have to do anything else with that I suppose? Yes. Put 'use Data::Dumper' anywhere before you first use it, and 'print Dumper \%fouls' after you've populated the hash. I actually did something like this when I had 1-d hashes, but six of them, one for every different foul(for simplicity's sake, I've just written names of 3 diff kinds of fouls), but then I thought I'd have to write a bunch of lines like you wrote for the 2-d hash, which I thought would be cumbersome, since there are plenty of different names. I wrote it that way so that it produced exactly the output that you proposed. The list of foul types is just the list of keys for the %fouls hash,so you could write foreach (keys %fouls) { : } I had something like: if ($3 eq 'Offensive') { $offensive{$1}++; } That's when he suggested that I didn't have to match $3 or $1 to anything, and so sent me on a chase to figure out how. That's how I came up with the thought that I'm not matching the name in the example above ($1) so perhaps I could write a line like so: $fouls{$3}{$1}++; and that would do the same thing if wrote: if ($1 eq 'Chan' and $3 eq 'offensive') { $fouls{$3}{$1}++; } or something like that. So this is what I'd like to do, count fouls without using string comparison operators. You're getting confused between variables and data here. $1, $3, $player, $type etc are all just scalar variables (except that you can't set $1 .. $9 yourself. Perl hash to set them from a regex.) What you're trying to write above is if ($1 eq 'Chan' and $3 eq 'offensive') { $fouls{offensive}{Chan}++; } but then you have to replicate this for every combination of player and foul type, which also means that you have to know what valid values to expect. This may be the case here, when you know what foul types are possible, but you don't want to have to change the program when the team members change. I hope you can see that this is the same as $fouls{$3}{$1}++; or $fouls{$player}{$type}++; without having to test the contents of the variables at all. I'm getting confused by the variable names and what each represent since the $1 or the $3 isn't in there. Scalar $type holds the foul type. The same as $3 on input. Scalar $player holds the player name. The same as $1 on input. Yes, but was supposed to assume that further up in the code I would have assigned $1 to $player, and $3 to $type? That's where a lot of my confusion came from. No. Forget about $1 and $3 once you've read your data into the hash. If you want particular values out of the data you can hard-code them like this: foreach my $type ( qw/Offensive Personal Shooting/ ) { my $rank = $fouls{lc $type}; : } or, if you just want all the data in the hash, in no particular order foreach my $type ( keys %fouls ) { my $rank = $fouls{lc $type}; : } Then, what does $rank refer to? Wait, it looks like it is assigned to $fouls{$type} Yes. so then $rank would have a key of foultype, and a value of player name which is also a key and would have a value of the number of fouls? Is that it? Careful now! $rank is a scalar variable,and happens to be a hash reference. Going back to the diagram, you've plucked one of the three first level branches off the tree and put it into $rank. The hash it references has the three player names as keys and their foul counts as values. and I'm not familiar with this syntax:
Re: Find regex in Start/Stop segments
Tassilo Von Parseval wrote: On Tue, Jun 10, 2003 at 11:49:25PM -0700 Harry Putnam wrote: ## Set a marker to know when we are in a new file $fname_for_line_cnt = ''; for (@files) { chomp; I don't think that the entries in @ARGV contain newlines at the end. Actually I know they don't. :-) Well it could happen but you would really have to want it that way. $ perl -le'for(@ARGV){print length; chomp; print length}' one 'two ' three 3 3 4 3 5 5 And of course, if you have a file name with an actual newline in it then you don't want to remove it. :-) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
On Wednesday, June 11, 2003, at 01:21 PM, Rob Dixon wrote: Time to go and play with hashes for a while! Start with the simplest imaginable hash my %hash; $hash{A} = 1; and dump it. Then add additional data, then additional levels, and get a feel for what the operations are doing. Just wanted to chime in and say, I think this is a super great idea! Stuart, I think you're close to getting your head around all of this, but in talking with you last week and then watching your conversation with Rob today, it's clear that you are getting tripped up by the hashes and references (in Perl, references are required for multidimensional hashes). Rob's really got the right idea here, go back to the basics and see how all this is working, then it should slide into place for you. Data::Dumper can really help this along, just like Rob said. Expanding on his idea a little, start with something like the following. See if you can run through how this is working. This is really just a simplified version of the things you are trying, minus references. Good luck and come back if you run into more questions. James #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %test; $test{Count} = 1; print First:\n, Dumper(\%test); $test{Count}++; print \nAfter ++:\n, Dumper(\%test); { # a block of code, for scope my $key = 'Count'; $test{$key}++; } # block ends, $key ceases to exist print \nAfter ++ via \$key:\n, Dumper(\%test); $test{$_}++ foreach 'A'..'Z'; print \nAfter 'The Seen ++ Trick':\n, Dumper(\%test); __END__; First: $VAR1 = { 'Count' = 1 }; After ++: $VAR1 = { 'Count' = 2 }; After ++ via $key: $VAR1 = { 'Count' = 3 }; After 'The Seen ++ Trick': $VAR1 = { 'S' = 1, 'F' = 1, 'T' = 1, 'N' = 1, 'K' = 1, 'Y' = 1, 'E' = 1, 'V' = 1, 'Z' = 1, 'Q' = 1, 'M' = 1, 'C' = 1, 'L' = 1, 'A' = 1, 'J' = 1, 'O' = 1, 'W' = 1, 'X' = 1, 'P' = 1, 'B' = 1, 'H' = 1, 'D' = 1, 'R' = 1, 'Count' = 3, 'I' = 1, 'G' = 1, 'U' = 1 }; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: very beginner
Dave Digregorio wrote: Could someone direct me to the correct module to use for monitoring an Internet connection? I just want to see the IP addresses of the machines trying to get into my PC. Get a progam like Ethereal: http://www.ethereal.com/ :-) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
mathing only one type of characters
Hi All; I would like to match a string if it has only cero or more of a defined set of characters. For example: if GACT are the characters, then GACTNGACT ## This string should not be matched because it has the extra character N GACCC ## This could be matched; Any help to solve this problem will be greatly appreciated. cheers *** PEDRO A. RECHE , pHDTL: 617 632 3824 Bioinformatics Research Scientist FX: 617 632 4569 Dana-Farber Cancer Institute, EM: [EMAIL PROTECTED] Molecular Immunology Foundation,EM: [EMAIL PROTECTED] Harvard Medical School, W3: http://www.mifoundation.org 44 Binney Street, D1510A, Boston, MA 02115 *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
File not getting written
Hi All: I added the following line to my program: $/ = \65536; This was because I'm running out of memory when slurping entire files into memory (potentially hundreds of meg). However, the (separate) log file I'm writing afterwards is not getting created - nor am I getting any error messages. If I comment this line out, it works fine. I tried the following: $opfh = select(OUTFILE); $| = 1; select ($opfh); ... to try and flush the buffer, but to no avail. Would someone tell me what I need to do to get this file written out please? TIA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Two lists...
Say I have two large lists of names (uid's). I would like to look at both of these files and make sure that a name (uid) doesn't appear in BOTH files. Just one or the other. Not sure how to handle that. Any ideas? Thanks. -James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: very beginner
Could someone direct me to the correct module to use for monitoring an Internet connection? I just want to see the IP addresses of the machines trying to get into my PC. Get a progam like Ethereal: http://www.ethereal.com/ or: netstat tcpdump lsof and roll your own with Socket or IO::Socket. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mathing only one type of characters
Pedro Antonio Reche wrote: Hi All; I would like to match a string if it has only cero or more of a defined set of characters. For example: if GACT are the characters, then GACTNGACT ## This string should not be matched because it has the extra character N GACCC ## This could be matched; Any help to solve this problem will be greatly appreciated. Hi Pedro. This will do what you want. HTH, Rob use strict; use warnings; foreach my $string ( qw/GACTNGACT GACCC/ ) { if ( $string !~ /[^GACT]/) { printf String %s passes test\n, $string; } else { printf String %s fails test\n, $string; } } OUTPUT String GACTNGACT fails test String GACCC passes test -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File not getting written
From: Rob Das [EMAIL PROTECTED] I added the following line to my program: $/ = \65536; It'd be better to use read FILE, $buffer, 65536; and leave $/ alone. Keep in mind that $/ is global and affects all filehandles you try to read from using the diamond operator (FILE). So if possible you should leave $/ and similar variables intact and if you really have to change them you should local()ize the change to the smallest possible block. This was because I'm running out of memory when slurping entire files into memory (potentially hundreds of meg). Then don't do that :-) Read and the process the files in chunks. However, the (separate) log file I'm writing afterwards is not getting created - nor am I getting any error messages. If I comment this line out, it works fine. I tried the following: $opfh = select(OUTFILE); $| = 1; select ($opfh); ... to try and flush the buffer, but to no avail. Would someone tell me what I need to do to get this file written out please? I don't know how could changing $/ prevent a file from being written. Except maybe is you try to read a line from the terminal after you change the $/ with $response = STDIN; In that case I'd expect this command to only return after the poor user types those 64KB of stuff. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File not getting written
Rob Das wrote: Hi All: I added the following line to my program: $/ = \65536; This was because I'm running out of memory when slurping entire files into memory (potentially hundreds of meg). However, the (separate) log file I'm writing afterwards is not getting created - nor am I getting any error messages. If I comment this line out, it works fine. I tried the following: $opfh = select(OUTFILE); $| = 1; select ($opfh); ... to try and flush the buffer, but to no avail. Would someone tell me what I need to do to get this file written out please? You need to comment out the line $/ = \65536; since it is preventing your log file from printing, and doing nothing else useful. (I suspect that it is being treated as a 16-bit integer and, since 65536 == 0x1, this is being evaluated as zero.) The buffer size cannot help you to accommodate overly large files. If you try to slurp the entirety of a file that will not fit into your virtual memory then you cannot do it - even by reading it in Very Big Chunks. I have never seen a problem whose solution needs all of a file's contents in memory simultaneously. Why not tell us what you are trying to do and how you have tried to do it. Then we will help. By the way, the cleanest way to autoflush a filehandle is use IO::Handle; autoflush OUTFILE; Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Two lists...
James Kelty wrote: Say I have two large lists of names (uid's). I would like to look at both of these files and make sure that a name (uid) doesn't appear in BOTH files. Just one or the other. Not sure how to handle that. Any ideas? The short answer is perldoc -q duplicate The long one is, what does 'make sure' mean? I can think of several ways, all more or less destructive, to make sure there are no duplicates between the files. But how about this code to /find out/ if there are duplicates; then you can wreak whatever destruction is appropriate. my %uids = do { local @ARGV = 'file1'; map { ($_, undef) } ; }; my $already = do { local @ARGV = 'file2'; grep {exists $uids{$_}} ; }; if ($already) { : } Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: trim function
Jair Santos wrote: Hi all, say that use strict;# always use warnings; # usually $directory = C:\\directory\\*.* Use single quotes for cuter code. my $directory = 'C:\directory\*.*'; and I am trying to remove the *.* from the end using $directory = trim($directory); where trim is sub trim { my( $result) = @_; $result =~ s/^\s+(.*?)\s+$/$1/; $result =~ s/\s//g; return $result; } Can anybody point me out why it is not working? Your 'trim' subroutine removes leading and trailing whitespace from the string - it has nothing to do with taking the path from a filename. Try this: use strict; use File::Basename; my $directory = 'C:\directory\*.*'; $directory = dirname $directory; print $directory, \n; OUTPUT C:\directory HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing a hash
James Edward Gray II wrote: On Wednesday, June 11, 2003, at 01:21 PM, Rob Dixon wrote: Time to go and play with hashes for a while! Start with the simplest imaginable hash my %hash; $hash{A} = 1; and dump it. Then add additional data, then additional levels, and get a feel for what the operations are doing. Just wanted to chime in and say, I think this is a super great idea! Thanks for the vote James. I must be doing something right. :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: trim function
Hi all, say that $directory = C:\\directory\\*.* and I am trying to remove the *.* from the end using $directory = trim($directory); where trim is sub trim { my( $result) = @_; $result =~ s/^\s+(.*?)\s+$/$1/; Because . And * have special meanings in a regex. And the ^ is looking for \s+ ( Whitespace) at the beginning of the string. Try $result =~ s/\*\.\*$//; Which says remove the *.* from the end of this string. HTH DMuey $result =~ s/\s//g; return $result; } Can anybody point me out why it is not working? TIA Jair -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
hex to dec and dec to hex
Is there an easy way to go back and forth between decimal and hex in perl. I know of the hex function which solves my hex to dec problem but how about a dec-hex function or module? I need the value which is why printf isn't working for me. Thanks for any help. -Ken The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: hex to dec and dec to hex
Ken Lehman [mailto:[EMAIL PROTECTED] : : Is there an easy way to go back and forth between : decimal and hex in perl. I know of the hex function : which solves my hex to dec problem but how about a : dec-hex function or module? I need the value which : is why printf isn't working for me. Are you aware of 'sprintf'? my $decimal_value = 10; my $hex_value = sprintf '%x', $decimal_value; HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: very beginner
Here is an example that i posted some time ago, : ~~ cut use Socket; use Fcntl; use POSIX; my $PORT=2100; my $proto=getprotobyname('tcp'); socket($socket,AF_INET,SOCK_STREAM,$proto) || die couldn't get socket: $!\n; bind($socket,sockaddr_in($PORT,INADDR_ANY)) || die couldn't bind: $!\n;; listen($socket,5) || die couldn't listen: $!\n;; print connected to: .inet_ntoa( (sockaddr_in( accept($remote_socket,$socket) ))[1] ); ~~~ paste - Original Message - From: Kipp, James [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 3:50 PM Subject: RE: very beginner Could someone direct me to the correct module to use for monitoring an Internet connection? I just want to see the IP addresses of the machines trying to get into my PC. Get a progam like Ethereal: http://www.ethereal.com/ or: netstat tcpdump lsof and roll your own with Socket or IO::Socket. -- 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: $SIG{__WARN__}
James Edward Gray II wrote: On Wednesday, June 11, 2003, at 05:27 PM, James Edward Gray II wrote: I'm setting the warning signal ($SIG{__WARN__}) to my own handler, redirecting warnings to my log file. It is working. I can see the call come through, but the passed @_ is completely empty. Shouldn't I be able to get the warning message out of there? Thanks for any insights. Sorry to reply to my own message, but I've figured out what's wrong and now I'm even more confused. I was doing: $SIG{__WARN__} = \my_warn(); ^^ Lose the parenthesis and it should work. $ perl -le' sub my_warn { print STDERR warn sub @_ } $SIG{__WARN__} = \my_warn(); warn HI ; ' warn sub Not a subroutine reference at -e line 4. $ perl -le' sub my_warn { print STDERR warn sub @_ } $SIG{__WARN__} = \my_warn; warn HI ; ' warn sub HI at -e line 4. When I changed it to the following, it started working: $SIG{__WARN__} = sub { HANDLE WARN CODE HERE }; Can someone please explain the difference between the two assignments to me? Thanks again. When you use the parenthesis perl calls the sub and in this context expects the return value to be a reference to a subroutine. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mathing only one type of characters
Pedro Antonio Reche wrote at Wed, 11 Jun 2003 13:38:18 -0500: I would like to match a string if it has only cero or more of a defined set of characters. For example: if GACT are the characters, then GACTNGACT ## This string should not be matched because it has the extra character N GACCC ## This could be matched; Any help to solve this problem will be greatly appreciated. Just another (from my point of view direct) view is $string =~ /^[GACT]*$/; The anchor stands for the beginning of the string, [GACT]* stands for zero or more of the defined characters $ stands for the end of the string. If you want to know more about regexps, read perldoc perlre Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: File not getting written
Hi Rob: I'm trying to merge a whole bunch of files (possibly tens of thousands) into one file. Here's my code (with the error checking removed for readability): opendir(INDIR, $indir); @logfile=grep(/$mask/i, readdir INDIR); closedir(INDIR); [EMAIL PROTECTED]; # number of files matching mask open(OUTFILE, $outdir$outfile); for ( $ctr=0; $ctr$nbrfiles; $ctr++ ) { open(INFILE, $indir$logfile[$ctr]); print OUTFILE INFILE; close(INFILE); } close(OUTFILE); Then I'm writing a file from the @logfile which then gets processed to delete the files. It's done this way for restartability, so if I fail after creating the merged file, I can restart and know which files need deleting. I'd appreciate an alternative to reading the entire file - you're right, I don't need the whole thing in memory at the same time. However, wouldn't processing the file one record at a time be much slower? I'll go that route if I have to... Thanks for your assistance Rob -Original Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 11, 2003 4:11 PM To: [EMAIL PROTECTED] Subject: Re: File not getting written Rob Das wrote: Hi All: I added the following line to my program: $/ = \65536; This was because I'm running out of memory when slurping entire files into memory (potentially hundreds of meg). However, the (separate) log file I'm writing afterwards is not getting created - nor am I getting any error messages. If I comment this line out, it works fine. I tried the following: $opfh = select(OUTFILE); $| = 1; select ($opfh); ... to try and flush the buffer, but to no avail. Would someone tell me what I need to do to get this file written out please? You need to comment out the line $/ = \65536; since it is preventing your log file from printing, and doing nothing else useful. (I suspect that it is being treated as a 16-bit integer and, since 65536 == 0x1, this is being evaluated as zero.) The buffer size cannot help you to accommodate overly large files. If you try to slurp the entirety of a file that will not fit into your virtual memory then you cannot do it - even by reading it in Very Big Chunks. I have never seen a problem whose solution needs all of a file's contents in memory simultaneously. Why not tell us what you are trying to do and how you have tried to do it. Then we will help. By the way, the cleanest way to autoflush a filehandle is use IO::Handle; autoflush OUTFILE; Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: References...
Hamish Whittal wrote: Thanks Rob, this has been very helpful. I wanted to know why the second form is an abuse of perl. Since I'm new to perl, it is helpful to kn ow what is good programming practise. Because it adds characters and notation that serve no purpose, which serves no purpose. There are more clear ways to write anything intended here: If you have a hashame and want an element: $config{$key} If you have a reference and you want the element $config_ref-{$key} $$config_ref{$key} ${$config_ref}{$key} All indicate what is happening more clearly. What actually happens in the case Rob cites is much more indirect, and invokes unnecessary processig. The only real reason to dereference a hash as a whole is to pass to functions calling for a hash, such as the keys function: foreach (keys %{$config_ref}) or oreach (keys %$config_ref) Otherwise you get there much faster and more cleanly by just playing off the reference, using the arrow operator. It may seem a bit cumbersome at first, but after you get used to it, it speaks very clearly of the process invloved with pointing from the reference given to the desired element or member function. Joseph Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]