Re: Need help with Data Structure: array of hash

2012-11-23 Thread Andy_Bach
I am having problem with array and Hash data structure. Example is show below: #CODE 1 my @list; my %this; $this{x} = 1; $this{y} = 2; $this{z} = 3; $this{Z} = 4; Better (maybe): my %this = ( x = 1, y = 2, z = 3, Z = 4, ) push @list, %this; The last

Re: How to split up a string with carriage returns into an array

2011-11-04 Thread Andy_Bach
I tried @ans = split (/\r/s, $msg); @ans = split (/\r/g, $msg); @ans = split (/\r\n/s, $msg); @ans = split (/\r\n/g, $msg); 2 things - Perl should handle the \r\n part for you - \n is normally a match for whatever your OS's end of line marker is. You also don't need the modifiers on the

RE: How to split up a string with carriage returns into an array

2011-11-04 Thread Andy_Bach
Parsing English is hard ;- but if you're fairly confident of the formatting, you can try and add in a marker and then split on that: $msg =~ s/((?:JAN|FEB|...|OCT|NOV|DEC)\s\d+\s\-)/|#|$1/g; @ans = grep { /\w/ } split('\|#\|', $msg); The elipsis there is the rest of the months (note, they

RE: Initialize variables in perl

2011-10-17 Thread Andy_Bach
is there a difference between my @variable; Creates a new, lexically scoped array. All the elements are undef. my @variable=(); The same, though it assigns an empty list to the array, sort of an explicit code comment This array is empty. Note, w/o the my this would empty an existing array.

RE: Help with array

2011-09-08 Thread Andy_Bach
It might also be worth taking a look at slices, described in 'perldoc perldata'. It also *may* be worth rethinking your data model. Often (not always but ...) needing to insert something into a particular location in an array implies a hash might be a better structure. Just a thought. a

RE: :Socket (client program sends simple text file containing CRLFnewlines)

2009-03-13 Thread Andy_Bach
I did a little googling and found Net::Telnet (built on top of IO::Socket) saying: In the input stream, each sequence of carriage return and line feed (i.e. \015\012 or CR LF) is converted to \n. In the output stream, each occurrence of \n is converted to a sequence of CR LF. See binmode() to

Re: implied variables (what are they actually?)

2009-03-10 Thread Andy_Bach
while () {#line1 print; #line2 } But so that I could add some better control of this program, can anyone please tell me what the ACTUAL VARIABLE name is that is being internally used in ?? (line 1)? And what ACTUAL VARIABLE name is being internally used in ?print;?

RE: Issue with Mail::Sender : what is the function called?

2009-03-05 Thread Andy_Bach
... but what exactly is the function called? It's called a here doc - it's a unix/shell convention, allowing multiline input: $ mail root EOM hi mom . EOM (old 'mail' ends w/ a '.' on line by itself) perldoc -q HERE.Doc Found in /usr/lib/perl5/5.8.0/pod/perlfaq4.pod Why don?t

Re: New to Perl and stuck

2009-03-03 Thread Andy_Bach
My goal is to automate this so that after specifying a folder, Perl will pull the specified lines from each of the 25 txt files in that folder and write them to a single output file. If you don't need file names etc, you can just expand your pointies to use a glob @output = *.txt but that

Re: trouble accessing fully qualified $main::variable contents

2008-07-07 Thread Andy_Bach
why I am unable to print the value of the main package's variable (despite that I am using the fully qualified variable name)? Name main::var used only once: possible typo at C:\perlsrc\TEST.PL line 9. Use of uninitialized value in concatenation (.) or string at c:\perlsrc\TEST.PL line 9.

Re: use FileHandle;

2008-04-17 Thread Andy_Bach
So, joyfully, I wrote the following: use FileHandle; foreach my $key (0 .. 34) { $fh = new FileHandle VTOL$key; $flist{$key} = $fh; print $flist{$key} Header info\n; } But it will not compile, it errors with: C:\VTOLparser.pl String found where operator expected at C:\VTOLparser.pl

Re: Questions on porting Perl from Unix to Windows

2008-01-24 Thread Andy_Bach
OS is found via the $^O (carrot capital O) special var: $ perl -e 'print $^O' linux I think winx stuff starts w/ MS C:\perl -e print $^O MSWin32 but you don't really want to do that. File::Copy $ perldoc File::Copy use File::Copy; copy(file1,file2) or die Copy failed: $!;

RE: Questions on porting Perl from Unix to Windows

2008-01-24 Thread Andy_Bach
It's a windows cmd.exe thing. Only dbl quotes work for -e script creation and there are a number of other issues. In general, one-liners in cmd.exe aren't going to be very useful. You can get a different shell (even bash) for winx but a Andy Bach Systems Mangler Internet: [EMAIL

Re: What is not initialised here?

2007-05-29 Thread Andy_Bach
$_ = shift @data until /Amount/; # start of transactions and get this warning: Use of uninitialized value in pattern match (m//) at CMS2AP.pl line 138. One way to avoid the warning is to check for that first uninit'ed $_ #!perl -w use strict; my @data = qw(hi ho hee ha Amount hoo hooh);

RE: How do I know where my Perl script is running?

2007-05-15 Thread Andy_Bach
2 ways of looking at your quesiton: FindBin: NAME FindBin - Locate directory of original perl script SYNOPSIS use FindBin; use lib $FindBin::Bin/../lib; or use FindBin qw($Bin); use lib $Bin/../lib; give you where the script itself is. The

Re: Perl Report Format Question

2007-05-08 Thread Andy_Bach
Why don't I Get IP addresses in the IP Address column of the report below. The data is there if I do a print after the split of the value in %GAA_Up foreach $GS_IPAddr (keys(%GAA_Up)) { open (UP, $GS_Report) || die Could not open file $GS_Report : $!\n;

Re: Newline in CGI script

2007-05-07 Thread Andy_Bach
The following code is live at http://www.biblescramble.com/Esther/x.cgi. I want to put newlines where the tabs are in $insert= Hazel Work states: WYrelocate: No; I've tried br, \n, etc. What do I need? Not sure what you're after, exactly. Perl will replace tabs by: $insert

Re: RES: Getting file name from a path

2007-04-13 Thread Andy_Bach
Often I need to extract the file name from a path. $current_file = c:/somedir/test.ps; @split_path = split(/,$current_file); $current_file = @split_path[-1]; print $current_file; You want to use the '$' sigil here, not '@' (you're refering to just one element, not the whole array):

Re: 3 dimensional hash of hashes

2007-02-22 Thread Andy_Bach
Just keep doing it ;- $tp3Lookup{$fileTypeKey}{$tpKey}) is your reference to the inner anon hash. Syntatic sugar pointers make it (to me) a little clearer $tp3Lookup{$fileTypeKey}-{$tpKey}) but foreach my $anonKey ( keys %{

Re: Counting Matches In A Line

2006-12-06 Thread Andy_Bach
wwang suggested: How about using split function? I mean something like: my @myCounts = split @YourData, /;/ print $#myCounts; Er, close - your split is reversed and you want to split the string, not an array: my @myCounts = split /;/, $YourData; but this points to an interesting thing we just

RE: Counting Matches In A Line

2006-12-05 Thread Andy_Bach
The match condition is number of ; in 1 line Output: found 14 ; in 1,232 lines found 13 ; in 7,456 lines found 12 ; in 2,321 lines my %line_counts; while () { my $semis = tr/;/;/; if ( $semis ) { $line_counts{$semis}++; } else { warn(Bad data - no semis: $_); }

Re: Regex Newbie Q: Non-Trivial Substitution and Modifying the Matched String

2005-10-10 Thread Andy_Bach
Not sure I'm getting it completely, but using match in a while loop w/ the /g modifier lets you process a string one match at a time: my $string = Lots of words to be read one at a time.\nthough more than one line; while ( $string =~ /(\w+)/g ) { print Found: $1\n; print Proceessing ...\n;

RE: Variable definition

2005-10-07 Thread Andy_Bach
To add a zero pad (printf if you just want it printed zero padded): my $padded_name = sprintf(%02d, $month); the 'zero' is the pad char, the '2' is the number of places to pad to To get rid of it: print The month number is: , $padded_name + 0, \n; that is, use it as an integer and Perl'll

Re: Script printing its own source code

2005-05-31 Thread Andy_Bach
... called quines ... And, in perl, one of the most amazing quine programs is Damian Conway's SelfGol. It's also the game of Life and a quine-izer for other programs - don't even think about looking at it. http://libarynth.f0.am/cgi-bin/twiki/view/Libarynth/SelfGOL I had the good fortune to

RE: count of matches

2004-12-23 Thread Andy_Bach
Try: #!/usr/bin/perl -w use strict; $_ = ABabcde12345BAABabcde1234blahblah5BA; print is: , $_ , \n; my $count = () = $_=~ /(AB.*?BA)/g; my @match = /(AB.*?BA)/g; print match: , join(, , @match), \n; print I matched $count times\n; The trick is: $_ =~ /../ applies the

RE: black box

2004-12-16 Thread Andy_Bach
Just a small point - the shebang on winx does help perl - it will use any command line options (e.g #!perl -Tw turns on taint and warnings) it finds in the shebang, regardless of the path. a Andy Bach, Sys. Mangler Internet: [EMAIL PROTECTED] VOICE: (608) 261-5738 FAX 264-5932 Call out

Re: regex help

2004-11-03 Thread Andy_Bach
$Bill wrote: ... and \1 is deprecated for $1. I believe that should read [thanks Greg!] ...and \1 is deprecated on the right side of s///. On the left side (as in any regexp), \1 and $1 differ. But as a holdover from sed, \1 means the same as $1 on the right side of the subst. \1 isn't the

RE: simple regex question

2004-10-15 Thread Andy_Bach
A further debug/syntax nitpick: print foo='$foo'\n; $foo =~ /([^.]+).txt/; $ans = $1; print ans='$ans'\n; best as: my ($foo, $ans); print foo='$foo'\n; if ( $foo =~ /([^.]+)\.txt/ ) { $ans = $1; } else { $ans=match failed on: $foo; } print ans='$ans'\n; if you check your

Re: Mason question

2004-10-06 Thread Andy_Bach
One guess: My intiial thought is that i need to see more info. My guess is that the mason interpreter isn't even getting those requests. I would try setting it up to use an HTML::Mason::CGIHandler object. There should be an example at http://www.masonhq.com/ a Andy Bach, Sys. Mangler

RE: named hash inside of hash

2004-06-08 Thread Andy_Bach
I don't understand this line: $ips{$source_ip}-{$dest_ip}++; how can you access and increment something that doesnt exist? Fancy name: autovivification - perl, w/ your best interests at heart (generally) knows what you want to do, so it automagically creates the source_ip hash entry (if it

Re: localtime no work

2004-05-26 Thread Andy_Bach
Because your -5 hours off of epoch time - i.e.:my ($secs, $mins, $hours, $mday, $mon, $year, undef, undef, undef) =localtime($endTime - $startTime);print "Elapsed time was $mon/$mday/$year - $hours:$mins:$secs\n";gives:Elapsed time was 11/31/69 - 18:0:10That isplus 10 seconds minus (in my case) 6

RE: getting file's date/time in Net::FTP

2004-04-20 Thread Andy_Bach
perldoc Net::FTP: dir ( [ DIR ] ) Get a directory listing of DIR, or the current directory in long format. In an array context, returns a list of lines returned from the server. In a scalar context, returns a reference to a list. so, for Solaris

Re: searching a file for keywords

2004-04-15 Thread Andy_Bach
You might do better to make an altenation: $keywords = join(|, @keywords); if ( $wholefile =~ /^\s*($keywords)\s*$/mo ) { # do you want 'i' ? rather than the loop. Worth a benchmark, but one search for multiple matches is probably faster than multiple searches for some sized files. You also

Re: Regex matching of patterns in variables

2004-03-03 Thread Andy_Bach
Works fine here - 'course the '.' in Wile E. is going to match any char so: Wile E. Coyote matches Wile Ej Coyote matches Wile E. Coyotexxx matches using quotemeta or \Q: #my $var = coyote; my $var = quotemeta Wile E. Coyote; while (DATA) { if ( /$var/oi) { print $_ . matches\n; }

Re: How to strip out EOF characters

2004-02-03 Thread Andy_Bach
Isn't it a little silly to go on to try and read from whichever file handle after the open has failed? You've got two flags set (errorcheck2 and error_flag), so at least use one to skip around the while . It looks like you're expecting to have a number of possible failures - make sure to

RE: Seemingly simple???

2003-12-10 Thread Andy_Bach
Perl uses the line ending appropriate for the platform \r\n for dos \n for *nix and translates the print hey\n appropriately. You can do: $var =~ s/\r//; to remove the ^M but you probably want to look into setting the var $/ and use chomp. perldoc -f chomp chomp This safer version of

Re: Sorting numbers?

2003-12-02 Thread Andy_Bach
one way: sort { $a +0 = $b + 0 } @msgs forces them to be treated as numbers, not strings. Hmm: @msglist = sort { $a = $b } @msgs; $found = $msglist[0]; for ($i = 0; $i scalar(@msglist); ++$i) { print Checking message $msgs[$i]\n; last if ($msglist[$i] == $message); } $found =

Re: What is this used for....

2003-11-07 Thread Andy_Bach
Its rude/bad/silly to post msgs to two lists at once, esp. as this is _javascript_ not perl but it appears to be a wanker's code to get folks to a web site in the Netherlands. All that:function rd() { var a = l3[4]+l1[8]+l2[4]+l1[3]+l2[5]+l3[4]; var b =

Re: echo %CD%

2003-09-25 Thread Andy_Bach
print `cd`; (those are back tics, not quotes) works. cd by itself, in winx returns the current dir. a Andy Bach, Sys. Mangler Internet: [EMAIL PROTECTED] VOICE: (608) 261-5738 FAX 264-5030 We are either doing something, or we are not. 'Talking about' is a subset of 'not'.--

Re: [OT:] RE: PDA language!

2003-06-23 Thread Andy_Bach
My Sharp Zaurus 5600 runs perl. a Andy Bach, Sys. Mangler Internet: [EMAIL PROTECTED] VOICE: (608) 261-5738 FAX 264-5030 We are either doing something, or we are not. 'Talking about' is a subset of 'not'.-- Mike Sphar in alt.sysadmin.recovery