Re: how to do this in perl (from unix)

2011-09-01 Thread John W. Krahn
John W. Krahn wrote: Rajeev Prasad wrote: from linux: cut -f1,5- -d file |grep -v ^0 | sort -n to_file;==this line: how to achieve this in perl? open IN_FH, '', 'file' or die Cannot open 'file' because: $!; open OUT_FH, '', 'to_file' or die Cannot open 'to_file' because: $!; print

Re: PCRE: Use backreference in pattern repetition bracket

2011-08-25 Thread John W. Krahn
Honza Mach wrote: Hi everybody, Hello, I was wondering, if it is possible to use backreferences in the pattern repetition bracket operator. Consider the following string: my $string = 5 abcdefghijklmn; The number five at the beginning of the string means, that I want to extract first five

Re: perl version 5.12

2011-08-22 Thread John W. Krahn
Danny Wong (dannwong) wrote: Hi All, Hello, I'm moving from perl version 5.8 to 5.12. In 5.8 code, I use the dbmopen function to read a perl db, but that function doesn't seem to work with version 5.12. any ideas if the function name changed or I need to use something else? Thanks.

Re: Find and Replace in Textfile

2011-08-22 Thread John W. Krahn
C.DeRykus wrote: If you're permitted a one-liner: perl -pi.bak -e '$c=s/Dood\/Dude/ if !$c++' file $ perl -c -pi.bak -e '$c=s/Dood\/Dude/ if !$c++' Substitution replacement not terminated at -e line 1. John -- Any intelligent fool can make things bigger and more complex... It takes a

Re: Find and Replace in Textfile

2011-08-21 Thread John W. Krahn
Ron Weidner wrote: Recently, I was asked to find the first occurrence of a word in a text file and replace it with an alternate word. This was my solution. As a new Perl programmer, I feel like this solution was too C like and not enough Perl like. So, my question is what would have been the

Re: Useless use of private variable

2011-08-20 Thread John W. Krahn
Ron Weidner wrote: In the program below the for loop is causing the warning... Useless use of private variable in void context at ./uselessUse.pl line 16. If I comment out the for loop like this the warning goes away... #for($i; $i $n; $i++) ^^ The first $i is in void context #{

Re: Sorting a String

2011-08-17 Thread John W. Krahn
Shlomi Fish wrote: Wagner, David --- Sr Programmer Analyst --- CFSdavid.wag...@fedex.com wrote: Since a \n is at end, then could use split like: for my $dtl ( sort {$a= $b} split(/\n/, $a_string) ) { One can also do split(/^/m, $a_string) to split into lines while preserving

Re: Sorting a String

2011-08-16 Thread John W. Krahn
Matt wrote: I believe you can sort an array like so: sort @my_array; That should be: @my_array = sort @my_array; I need to sort a string though. I have $a_string that contains: 4565 line1 2345 line2 500 line3 etc. Obviously \n is at end of every line in the string. I need it sorted.

Re: Variable Assignment

2011-08-16 Thread John W. Krahn
Joseph L. Casale wrote: What is the correct way to quickly assign the result of a regex against a cmdline arg into a new variable: my $var = ($ARGV[0] =~ s/(.*)foo/$1/i); my ( $var ) = $ARGV[0] =~ /(.*)foo/i; John -- Any intelligent fool can make things bigger and more complex... It takes

Re: Using unpack for bits

2011-08-14 Thread John W. Krahn
th0ma5_ander...@yahoo.com wrote: Hi all, Hello, When converting a single number (eg 6) to its binary format using unpack as in: unpack 'B8', '6'; # output = 00110110 You are not converting the number 6, you are converting the string '6'. I get the 8 character output 00110110. Does

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread John W. Krahn
Peter Scott wrote: On Thu, 11 Aug 2011 16:17:51 -0700, siegfried wrote: This works! Really? I get find: missing argument to `-exec' I think your command also renames directories. You want that? Is there a way to do it with less typing? How can I do it without creating a temporary

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread John W. Krahn
Randal L. Schwartz wrote: John == John W Krahnjwkr...@shaw.ca writes: John split() uses @_ by default so you could just say: That's deprecated though, if not already gone. (Looks gone in Perl 5.14.) It was a readily-admitted misfeature. Unless you're playing golf. :-) John -- Any

Re: I am going through github perl code

2011-08-11 Thread John W. Krahn
Emeka wrote: Hello All, Hello, What is the purpose of colon here ? sub pop : method { my $self = shift; my ($list) = $self-_prepare(@_); pop @$list; my $result = $list; return $self-_finalize($result); } perldoc perlsub SYNOPSIS To declare subroutines:

Re: How to grab last element of array from split with no temporary variables?

2011-08-11 Thread John W. Krahn
Shawn H Corey wrote: On 11/08/11 07:17 PM, siegfr...@heintze.com wrote: This works! Is there a way to do it with less typing? How can I do it without creating a temporary variable @p? Thanks, siegfried find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split /; rename $_, ./$p[$#p].txt } ' find

Re: Search and replace w/ ignoring arbitrary characters

2011-08-08 Thread John W. Krahn
Frank Müller wrote: dear all, Hello, i want to make some search and replace within a string where I can define a set of characters, especially parenthesis, brackets etc., which are to be ignored. For example, I have the following string: sdjfh sdf sjkdfh sdkjfh sdjkf f[o]o(bar) hsdkjfh

Re: Parsing a Text File using regex

2011-08-04 Thread John W. Krahn
timothy adigun wrote: Hi Ryan, Try the the code below, it should help. ==CODE= #!/usr/bin/perl -w use strict; my $ln=; my ($yr,$cat,$win)=(,,); my $filename=New_output.txt; chomp(my $raw_file=@ARGV); That is the same as saying: chomp( my $raw_file = glob @ARGV

Re: open files in a directory

2011-08-01 Thread John W. Krahn
homedw wrote: hi all, Hello, i want to open some files in a directory, you can see the details below, #!/usr/bin/perl -w use strict; opendir (FH,'C:\Player'); chdir 'C:\Player'; for my $file(readdir FH) { open DH,$file; foreach my $line(DH) {

Re: Characters

2011-08-01 Thread John W. Krahn
Emeka wrote: Hello All, Hello, I would like to know how to access character from string lateral. Say I have $foo = From Big Brother Africa; I would want to print each of the characters of $foo on its own. In some languages string type is just array/list of characters. What is it in Perl?

Re: perl reference

2011-07-30 Thread John W. Krahn
Rajeev Prasad wrote: Hello, Hello, from here: http://www.troubleshooters.com/codecorn/littperl/perlsub.htm i found: In Perl, you can pass only one kind of argument to a subroutine: a scalar. To pass any other kind of argument, you need to convert it to a scalar. You do that by passing a

Re: Any suggestion on how to improve this code? Malformed braces

2011-07-28 Thread John W. Krahn
newbie01 perl wrote: Hi all, Hello, I've written a Perl script below that check and report for malformed braces. I have a UNIX ksh version and it took a couple of minutes to run on a 1+ lines. With the Perl version it only took about 20 seconds so I decided to do it the Perl way. Besides

Re: Exit subroutine on filehandle error

2011-07-26 Thread John W. Krahn
Nikolaus Brandt wrote: Hi, Hello, I'm currently writing a script which contains a subroutine to write data to files. Currently I use open $fh, '', $basedir/$userdir/$outfile or die Can't write: $!\n; which has the disadvantage, that the whole script dies if e.g. the userdir is not available.

Re: parsing script duplication of lines issue, please advise

2011-07-21 Thread John W. Krahn
Rob Dixon wrote: After these changes, the loop looks like this while (IN){ chomp; my @line=split(/\t/); if ($line[3] == -1) { print OUT $_\n; } } You can make it much simpler than that: while ( IN ) { print OUT if /\t-1$/; } John -- Any intelligent fool can

Re: first post

2011-07-20 Thread John W. Krahn
H Kern wrote: Hi, Hello, My first newbie post. I wish to have two arrays indexed by a hash table. The simple program below runs and behaves properly initializing the hash table with the information I wish it to have. However, Perl generates the following suggestion on the @header{}

Re: grep question

2011-07-19 Thread John W. Krahn
Steven Surgnier wrote: Hi, I desire a concise conditional statement which simply checks if each entry in an array matches a given string. For example: print all the same if (grep {m/test_name/} @bins) == scalar @bins); #END CODE I thought, grep will return the number of matches, so why not

Re: File::Find script questions

2011-07-18 Thread John W. Krahn
Marc wrote: I've written a script to traverse my web server, find any files called error_log, e-mail them to me, and then delete them. It is triggered by cron twice a day. The script works great but I'd like to get advice on how I can clean up my code, so any comments are welcome. Also, do I

Re: Help Parsing a Tab delimited file

2011-07-14 Thread John W. Krahn
C.DeRykus wrote: Basically, the one-liner reads the tab-delimited file line by line (-n); autosplits fields the line into fields based on whitespace (- a) and populates @F with those fields. If the 2nd column $F[1] , hasn't been seen or differs with the previous line's 2nd col., then a new

Re: print output on console at runtime

2011-07-13 Thread John W. Krahn
Irfan Sayed wrote: hi, Hello, i need to print the output of a command on the console at runtime lets say, i need to execute find command .as of now , what i am doing is , @cmd= `find . -name abc`; print @cmd\n; now what happens is, once the command completed then it will send entire

Re: Best way to parse this type of data.

2011-07-11 Thread John W. Krahn
shadow52 wrote: Hello Everyone, Hello, I have finally hit my max times of banging my head on the best way to parse some data I have like the following below: name = Programming Perl distributor = O'Reilly pages = 1077 edition = 2nd Authors = Larry Wall Tom Christiansen Jon Orwant The last

Re: Creating letter combination generator

2011-07-09 Thread John W. Krahn
Robert wrote: I have currently wrote a simple script to attempt to create a list of every letter combination this is a rough outline of what I want my program to do . . . A B C ... AA AB AC perl -le'print for A .. ZZ' I used perl a bit for a high school project several years ago so I'm not

Re: Different behaviour

2011-07-07 Thread John W. Krahn
HACKER Nora wrote: Hello, Hello, I would be really glad if someone could give me a hint to my following problem: I have a script that runs smoothly on AIX5.3, installed Perl is 5.8.8. Now I need it to run on AIX6.1, Perl is 5.8.8 as well, but I experience a strange, differing behaviour. I

Re: Lock file question

2011-06-22 Thread John W. Krahn
Steven Buehler wrote: From: Jim Gibson [mailto:jimsgib...@gmail.com] On 6/22/11 Wed Jun 22, 2011 3:02 PM, Steven Buehler st...@ibushost.com scribbled: I am trying to use a lockfile so that the script can't be run again if it is already running. The below code works fine. The problem is

Re: how to write a range of 10 to 80 as a regular expresssion

2011-06-21 Thread John W. Krahn
eventual wrote: Hi, Hello, Looking at the script below, how do I write a range of 10 to 80 as a regular expression. I tried [10 - 80] but it wont work. Thanks # script ## #!/usr/bin/perl my $player_total_points = 70; if ( $player_total_points =~/^(10..80)$/ ){ print

Re: trying to match non ascii chars

2011-06-17 Thread John W. Krahn
Chris Knipe wrote: Hi, Hello, I have bit of problem with transparent squid service. When people tries to send binary data through squid, the log files naturally doesn't like it very much. A sample of such an log file entry: 1308293915.456 0 client.host.name NONE/400 3660

Re: Re : Re: Re : Re: Check if words are in uppercase?

2011-06-15 Thread John W. Krahn
Rob Dixon wrote: On 15/06/2011 12:10, Paul Johnson wrote: #!/usr/bin/perl use strict; use warnings; my @keywords = qw ( abs access after alias all and architecture array assert attribute begin block body buffer bus case component configuration constant disconnect downto else elsif end entity

Re: how to use regexp to match symbols

2011-06-13 Thread John W. Krahn
eventual wrote: Hi, Hello, I have a list of mp3 files in my computer and some of the file names consists of a bracket like this darling I love [you.mp3 I wish to check them for duplicates using the script below, but theres error msg like this Unmatched [ in regex; marked by-- HERE in m/only

Re: Check if words are in uppercase?

2011-06-10 Thread John W. Krahn
Beware wrote: Hi all, Hello, i've a question on my perl script. In my script i read a file line per line, and check if keywords are in uppercase. To do that, i've an array filled with all used keywords. On each line, i check all keywords with a foreach loop. Well, this is my code : my

Re: Adding file contents into hashes

2011-06-07 Thread John W. Krahn
venkates wrote: Hi, Hello, This is a snippet of the data ENTRY K1 KO NAME E1.1.1.1, adh DEFINITION alcohol dehydrogenase [EC:1.1.1.1] PATHWAY ko00010 Glycolysis / Gluconeogenesis ko00071 Fatty acid metabolism ko00350 Tyrosine metabolism ko00625 Chloroalkane and chloroalkene degradation

Re: perl code for if-elsif-else logic

2011-06-02 Thread John W. Krahn
Anirban Adhikary wrote: Hi list Hello, I have wirtten the following perl code which has some configuration params such as prefix,suffix,midfix and nofix. The logic is filenames will be selected based on prefix,suffix and midfix pattern.After the fiter through above 3 patterns if file names

Re: script to create to create tar and place files in the appropriate folder

2011-05-31 Thread John W. Krahn
Brandon McCaig wrote: Hello, Just a couple of comments on some of your code. :) my $start_line = 2; unless($lines[1] =~ /^\s*$/) { warn The second line isn't empty ; $start_line--; } @lines = @lines[$start_line..$#lines]; You are copying

Re: script to create to create tar and place files in the appropriate folder

2011-05-31 Thread John W. Krahn
Uri Guttman wrote: JWK == John W Krahnjwkr...@shaw.ca writes: JWK Or as: JWK $_ = $directory/$_ for @dirfiles[ 1 .. $#dirfiles ]; just to show another way that is usually faster for prepending a string: substr( $_, 0, 0, $directory/ ) for @dirfiles[ 1 ..

Re: binmode in perl -p oneliner Optionen

2011-05-28 Thread John W. Krahn
Thomas Liebezeit wrote: Hello, Hello, I'm triying to do some substitutions on an pdf file. perl -p -i~ -w -e s/A/B/; file.pdf This works as intended, except: perl adds 0x0D (Windows \n) :-/ as a HEX diff shows. How can I work around this? Is there something like binmode()? You

Re: script takes long time to run when comparing digits within strings using foreach

2011-05-28 Thread John W. Krahn
eventual wrote: Hi, Hello, I have an array , @datas, and each element within @datas is a string that's made up of 6 digits with spaces in between like this “1 2 3 4 5 6”, so the array look like this @datas = ('1 2 3 4 5 6', '1 2 9 10 11 12', '1 2 3 4 5 8', '1 2 3 4 5 9' , '6 7 8 9 10 11');

Re: Rsync options not recognized by system function

2011-05-27 Thread John W. Krahn
Uri Guttman wrote: ET == Ezra Taylorezra.tay...@gmail.com writes: ET Hello All: ET My rsync options are not being recognized in the system ET function. I tried escaping the asterisks and single quotes to no avail. ET Also, I do not want to install any rsync

Re: split re

2011-05-15 Thread John W. Krahn
Mike McClain wrote: In reading in a file of space separated columns of numbers and stuffing them into an array, I used: while( my $line =$FH ) { my @arr = split /\s+/, $line; push @primes_array, @arr; } but kept getting empty array entries until I switched to:

Re: How to convert to array? Why so many parens?

2011-05-12 Thread John W. Krahn
siegfr...@heintze.com wrote: Darn -- I forgot to switch to plain text again. I hope this does not appear twice -- I apologize if it does! This works and produces the desired result (I've simplified it a bit): $default= `grep pat file-name`)[0])=~/[0-9]+/)[0]); I think you mean either:

Re: help me with a parsing script please

2011-05-12 Thread John W. Krahn
Nathalie Conte wrote: HI, Hello, I have this file format chr start end strand x 12 24 1 x 24 48 1 1 100 124 -1 1 124 148 -1 Basically I would like to create a new file by grouping the start of the first line (12) with the end of the second line (48) and so on the output should look like

Re: gettting rid of whitespace characters

2011-05-10 Thread John W. Krahn
Irene Zweimueller wrote: Dear list, Hello, I´m relatively new to Perl, so please be patient. Welcome to Perl and the beginners list. I tied to get rid of whitespace characters by the following programme: my $i= USEFUL ; if ($i =~ /\s/) { $i =~

Re: how to redefing the default list seperator

2011-05-05 Thread John W. Krahn
eventual wrote: Hi, How do I change the default list seperator. I tried the following but it wont work. Thanks $testing = anything in here; @rubbish = $testing; You are assigning one scalar value to the whole array so only $rubbish[0] will have any content. $ = in; This is the correct

Re: retrieving key from hash of hashes

2011-04-29 Thread John W. Krahn
Agnello George wrote: Hi All Hello, I got a hash like this : my %retrn = ( 0 = { 0 = ' successfulbr'}, 1 = { 1 = 'insufficientbr'}, 2 = { 2 = 'txtfile missingbr'}, 3 = { 3 = 'bad dirbr'}, ); ( i know this hash looks funny , but is the hash i

Re: regular expression

2011-04-28 Thread John W. Krahn
Irfan Sayed wrote: hi, Hello, i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz Whitespace is something that applies only to regular expressions but the second part of the

Re: regular expression

2011-04-28 Thread John W. Krahn
John W. Krahn wrote: Irfan Sayed wrote: i have following code. $target = abc,xyz; print $target\n; $target =~ s/,/\s/g; print $target\n; i need to replace comma with whitespace for string abc,xyz Whitespace is something that applies only to regular expressions but the second part

Re: How does this work?

2011-04-27 Thread John W. Krahn
Owen wrote: There is a person on the Internet using this to advise his email address. perl -le print scalar reverse qq/moc.liamg\100halbhalb/ I am intrigued as to how 001\ becomes @ \100 is interpolated as @ before the string is reversed. You could also write that as: perl -le print

Re: How does this work?

2011-04-27 Thread John W. Krahn
Jeff Pang wrote: 2011/4/27 Tim Lewistwle...@sc.rr.com: If needed, there is a good complete table of the ASCII values at http://www.asciitable.com/ Good resource. BTW, what do Hx and Oct in the table mean? And what's the difference between them? Hx = hexadecimal Oct = octal Hexadecimal is

Re: move array elements to hash

2011-04-16 Thread John W. Krahn
mark baumeister wrote: Hi, Hello, I am trying to move array elements (populated from theSTDIN) into a hash as pairs [i] and [i + 1] and then print them out using the code below. If I enter bob as the first element and hit enter I get the error messages below. I guess there are multiple

Re: help in scripting

2011-04-16 Thread John W. Krahn
Shlomi Fish wrote: On Saturday 16 Apr 2011 09:06:02 Gurunath Katagi wrote: hi .. i am new to perl .. i have a input file something pasted as below .. 16 50 16 30 16 23 17 88 17 99 18 89 18 1 .. -- and i want the output something like this : 16 50 30 23 17 88 99 18 99 1 i.e for each values in

Re: help in scripting

2011-04-16 Thread John W. Krahn
[ Please do not top-post. TIA ] tianjun xu wrote: This works. #!/usr/bin/perl use strict; use warnings; my %hash=(); while(){ chomp(my $line=$_); my($col1, $col2)=split(/\s+/, $line); Or just: while ( ) { my ( $col1, $col2 ) = split; push(@{

Re: Regular expression to capitalize first letter of words in sentence

2011-04-13 Thread John W. Krahn
Shlomit Afgin wrote: Hi Hello, I need to write regular expression that will capitalize the first letter of each word in the string. Word should be string with length that is greater or equal to 3 letters exclude the words 'and' and 'the'. I tried: $string = lc($string); $string =~

Re: How to test for 2 words from a list in a form field?

2011-04-10 Thread John W. Krahn
shawn wilson wrote: heh, i've got to learn to test my code before posting - i'm ending looking like an idiot :) *sigh* this is what i wanted to say: #!/usr/bin/perl use warnings; use strict; my $fields1 = a little sentense with one and it will match with two\n; my $fields2 = this one will

Re: pushs in xs

2011-04-10 Thread John W. Krahn
shawn wilson wrote: On Apr 8, 2011 4:42 PM, Uri Guttmanu...@stemsystems.com wrote: While I don't agree with uri's reaction to the post, xs ain't beginner (but something this 'beginner' has been thinking of getting into recently). as for other places, google helps. there is usenet (still

Re: issue wit sysopen

2011-04-10 Thread John W. Krahn
shawn wilson wrote: On Apr 10, 2011 4:05 AM, Sunita Rani Pradhansunita.prad...@altair.com wrote: sysopen(DATA,list1.txt,O_RDWR|O_TRUNC); Why not just use open with + ? I've never seen the benefit of sysopen unless you're working with a stream. Also, I don't know those options are

Re: issue wit sysopen

2011-04-10 Thread John W. Krahn
Shlomi Fish wrote: On Sunday 10 Apr 2011 11:03:51 Sunita Rani Pradhan wrote: $i =~ s/d|b/G/ig; Thsi should be : $line =~ s/[db]/G/ig; Or possibly even: $line =~ tr/dbDB/G/; John -- Any intelligent fool can make things bigger and more complex... It takes a

Re: Regular Expressions Question

2011-04-10 Thread John W. Krahn
cityuk wrote: Dear All, Hello, This is more of a generic question on regular expressions as my program is working fine but I was just curious. Say you have the following URLs: http://www.test.com/image.gif http://www.test.com/?src=image.gif?width=12 I want to get the type of the image,

Re: trouble matching words with parentheses using grep

2011-04-09 Thread John W. Krahn
Mariano Loza Coll wrote: Hello everyone, Hello, Here's what I need to do: I need to take each of the words in one List1, search for their presence (or not) in a second List2 and make a new list with all the words in both. These are lists of gene names, which can often include numbers and

Re: How to test for 2 words from a list in a form field?

2011-04-09 Thread John W. Krahn
shawn wilson wrote: On Sat, Apr 9, 2011 at 3:29 PM,sono...@fannullone.us wrote: It is detecting but not testing if any particular 2 words are in a text field and I think that's what you explained you were testing for. Sorry if my first post was misleading. Those were just some

Re: Capturing the output of a shell command

2011-04-05 Thread John W. Krahn
Shawn H Corey wrote: On 11-04-05 09:24 AM, ANJAN PURKAYASTHA wrote: Hi, Is there any way to run a shell command from within a perl script and capture the output in, say, an array? One can run a shell command through the system function. But system itself just returns a status code. You could

Re: recursive ref value match

2011-04-03 Thread John W. Krahn
shawn wilson wrote: this is pretty abstract from what i'm really doing, but i'll put in the blurb anyway... i'm using CAM::PDF to parse data. this works well. however, i am trying to extract information out of a table. so, i want to find certain keys, then go up 3 levels and grab the position

Re: How can I do this in Perl?

2011-04-03 Thread John W. Krahn
Wernher Eksteen wrote: Thank you for correcting and showing me a better different way to do the while loops, but instead of the two for loops printing the following out: emcpowera sdbd sddg sdfj sdhm # - [1st for loop output] emcpoweraa sdae sdch sdek sdgn # These the available

Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread John W. Krahn
Wernher Eksteen wrote: Hi, Hello, How do I compare the column 1 in %hash2, with column 1 in %hash1 so that when a match is found to append or concatenate the hash key (column 1) and it's associated values from %hash2 with that of %hash1 and build a new hash %hash3 as the end result. %hash1

Re: How can I do this in Perl?

2011-04-02 Thread John W. Krahn
Wernher Eksteen wrote: Hi, Hello, The Perl script (shown further down below) gives me the following output (without the comments). Please note that this is not the complete output, I only show the necessary detail for sake of clarity. emcpowerasdbd sddg sdfj sdhm #- [1st

Re: parsing a delimited file

2011-04-01 Thread John W. Krahn
Anirban Adhikary wrote: Hi List Hello, I am trying to parse the following file and load it into a hash. File Structure DN: 2570764 (PORTED-IN) TYPE: SINGLE PARTY LINE SNPA: 438 SIG: DTLNATTIDX: 4 XLAPLAN KEY : 438CAUC1RATEAREA KEY :

Re: parsing a delimited file

2011-04-01 Thread John W. Krahn
Anirban Adhikary wrote: I want to create a new file where I get each line like KEY=VALUE In the source file in a single line the are multiple KEY-VALUE pair and there is also some line where KEY VALUE pair spreads across two lines. That's nice. Please do not top-post your replies. And please

Re: transposing %d values to %x output

2011-03-30 Thread John W. Krahn
Shawn H Corey wrote: On 11-03-29 07:50 PM, Noah Garrett Wallach wrote: s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$1:$2:$3:$4::0/ so is there a slick, easily readable way to get the value $1, $2, $3, $4 to be rewriten as %x instead of a %d?

Re: transposing %d values to %x output

2011-03-30 Thread John W. Krahn
Uri Guttman wrote: JWK == John W Krahnjwkr...@shaw.ca writes: JWK Shawn H Corey wrote: On 11-03-29 07:50 PM, Noah Garrett Wallach wrote: s/(\d+)\.(\d+)\.(\d+)\.(\d+)/$1:$2:$3:$4::0/ so is there a slick, easily readable way to get the value $1, $2, $3, $4 to be

Re: How to not hard code STDIN?

2011-03-30 Thread John W. Krahn
siegfr...@heintze.com wrote: I apologize if this appears twice. Since I sent it once and forgot to abandon HTML in favor of plain text, I'm sending it again. This works: $ perl -e ' $s = STDIN ; print $s\n; ' I don't like it because STDIN is hard coded. What if I want to conditionally read

Re: perl dd

2011-03-30 Thread John W. Krahn
Uri Guttman wrote: O == Owenrc...@pcug.org.au writes: O This will generate 1 files in less than a second. They are 0 size, O so just write something into them if you don't wont zero sized files might as well clean this up. O #!/usr/bin/perl O use strict; O my $file =

Re: ternary operator

2011-03-25 Thread John W. Krahn
Chas. Owens wrote: On Thu, Mar 24, 2011 at 16:53, Chris Stinemetz cstinem...@cricketcommunications.com wrote: I have a ternary operator that I would like to be rounded to the nearest tenth decimal place before the array is pushed. The proper term is conditional operator, even in C.

Re: foreach loop

2011-03-24 Thread John W. Krahn
Jim Gibson wrote: On 3/24/11 Thu Mar 24, 2011 9:04 AM, Chris Stinemetz cstinem...@cricketcommunications.com scribbled: $sum{$cell}{$sect}{$carr} += $rlp1 += $rlp2 += $rlp3 += $rlp4 || 0 ; } I see you are changing your program requirements. You are now accumulating multiple rlp values

Re: Twisting Text

2011-03-23 Thread John W. Krahn
Emeka wrote: Hello All, Hello, I have a file containing dictionary of words ... I would like to play with the file in this way. Say I pick a word Heaves . I would like to find other words that could be derive from Heaves Have, Haves, eave , eaves, Has, see, eves and so on. I would not want

Re: ip address substitution

2011-03-16 Thread John W. Krahn
Jim wrote: I propose the following code will properly take the variable $read_line and substitute $new_ip_address for all occurrences of $old_ip_address. Basically the snippet of code is from some software that will update a set of old ip addresses with new ip addresses within a file. Can anyone

Re: ARGV Error

2011-03-16 Thread John W. Krahn
Olof Johansson wrote: On 2011-03-16 22:51 +0700, ind...@students.itb.ac.id wrote: if(@ARGV != 1){ print ARGV error \n; print firstradar velx vely \n; exit(1); } ... I got this error message : ARGV error firstradar velx vely This is your output if the number of arguments

Re: ARGV Error

2011-03-16 Thread John W. Krahn
Shlomi Fish wrote: On Wednesday 16 Mar 2011 17:51:19 ind...@students.itb.ac.id wrote: if(@ARGV != 1){ 1. There should be a space before the {. There could be, but there doesn't have to be. print ARGV error \n; print firstradar velx vely \n; You should output errors STDERR -

Re: Permission bit translator?

2011-03-10 Thread John W. Krahn
newbie01 perl wrote: Hi, Hello, Does anyone know of any permission bit translator? One that can translate the permission bit from its textual value to its octal value and vice versa. It is alright if it is always just rwx but on a lot of occasions nowadays, getting a lots of s, S, t, etc.

Re: multidimensional array check

2011-03-08 Thread John W. Krahn
vito pascali wrote: Ok ppl, after some hard work (for me at least!!) that's what I got: #!/usr/bin/perl -w use strict; use warnings; use DBI; use DBD::mysql; use warnings; my ( $db_gal,$db_gal2,$db_lab,$tbl_ary_ref_g1,$tbl_ary_ref_g2,$tbl_ary_ref_l1 ); You should declare your variables in

Re: reading files and scope of $_

2011-02-24 Thread John W. Krahn
D wrote: I ran into something that I need help understanding. In the attached script, subroutine file_proc1 converts all elements of @molec to undef, while file_proc2 does not. adjusting file_proc1 to first slurp the file into an array fixes it. My best guess (via dum_sub) is that the

Re: Help on a socket problem

2011-02-24 Thread John W. Krahn
Ted Mittelstaedt wrote: On 2/23/2011 11:32 PM, John W. Krahn wrote: Ted Mittelstaedt wrote: Think of this as a chance to educate. If you were teaching a math class in elementary school and a child asked how to add 2 + 2 would you tell them to get a calculator? The NNTP protocol is very simple

Re: Help on a socket problem FIX

2011-02-24 Thread John W. Krahn
Ted Mittelstaedt wrote: OK since nobody helped me (sniff, sniff) I had to figure it out myself. Here is the problem code in the fragment: $sockaddr = 'S n a4 x8'; replacing it with $sockaddr = 'x C n a4 x8'; fixed the problem. The template for the pack command was wrong. Th first two bytes

Re: Help on a socket problem

2011-02-23 Thread John W. Krahn
Ted Mittelstaedt wrote: Think of this as a chance to educate. If you were teaching a math class in elementary school and a child asked how to add 2 + 2 would you tell them to get a calculator? The NNTP protocol is very simple and this only uses a few of it's commands. The code works on older

Re: Assistance with regular expression

2011-02-14 Thread John W. Krahn
William Muriithi wrote: Pal, Hello, I have to files that I am trying to match: I think you mean two files? Generated from rpm -qa file1 file1 libstdc++-4.1.2-48.el5 info-4.8-14.el5 libICE-1.0.1-2.1 libacl-2.2.39-6.el5 lcms-1.18-0.1.beta1.el5_3.2 dmidecode-2.10-3.el5 ... Generate

Re: print $myhash{key} gets SCALAR(0x1b8db540) instead of 0

2011-02-09 Thread John W. Krahn
gry wrote: [[v5.8.8 built for x86_64-linux-thread-multi] #!/usr/bin/perl -W use Getopt::Long; my $dml = 0; my $iterations = 10; my %options = (dml! = \$dml, iterations=i = \$iterations); GetOptions(%options) || die bad options; printf dml=$dml\n; That should be either: print

Re: date handle

2011-01-30 Thread John W. Krahn
p...@mail.nsbeta.info wrote: $ perl -MTime::Local -le 'print timelocal(0,0,0,1,1,1900)' Cannot handle date (0, 0, 0, 1, 1, 1900) at -e line 1 why Time::Local can't handle the date of 1900? Unix time starts at 1 Jan. 1970 so a time in 1900 is invalid. John -- Any intelligent fool can make

Re: array like split of string

2011-01-23 Thread John W. Krahn
Peter K. Michie wrote: I have this regex expression in a script that appears to do an array like split of a string but I cannot figure out how it does so. Any help appreciated $fname = ($0 =~ m[(.*/)?([^/]+)$])[1] ; print 7 $errlog\n; $fpath = ($0 =~ m[(.*/)?([^/]+)$])[0] ; print 8 $errlog\n;

Re: regex for matching Google URLs

2011-01-17 Thread John W. Krahn
Alexey Mishustin wrote: 1/18/2011, Grantemailgr...@gmail.com вы писали: I came up with these but they don't seem to work reliably: /\.google\..*\/imgres\?/ /\.google\..*\/images\?/ /\.google\..*\/products\?/ /(www.){0,1}(google\.).*\/(imgres)|(images)|(products)\?{0,1}/ That says:

Re: genbank library file

2011-01-16 Thread John W. Krahn
galeb abu-ali wrote: Hi, Hello, I'm trying to create a genbank library file that contains several genbank records. I read in the genbank record names from a separate file into an array and then loop through array of file names, open each file and read contents into another array. The problem

Re: Labelling Radio Group Values

2011-01-12 Thread John W. Krahn
Stephen Allen wrote: I have sucessfully created as Radio-group along the lines of @TiesArray = SSDArray($uniqueorgref); if (@TiesArray[0] ne ) { You are testing a list against a scalar value, but fortunately your list has only one element. If you had warnings enabled then perl would have

Re: Return value from function

2011-01-12 Thread John W. Krahn
Octavian Rasnita wrote: From: Parag Kalra paragka...@gmail.com On shell, successful command returns exit status of 0. As a best practice what status value shall a Perl function return. Going by the fact that Perl function returns the value of last command in it, I think function should

Re: calculate average

2011-01-11 Thread John W. Krahn
Dr.Ruud wrote: On 2011-01-08 03:16, S.F. wrote: I have a data file with n columns and r row. The first 3 columns and the first 5 rows are: 2 3 1 1 6 X 4 0 X X 8 X 5 X 5 The X means missing. How could I write a script to calculate the average by column and replace X with the average? The

Re: Map function, what does it do?

2011-01-11 Thread John W. Krahn
shawn wilson wrote: On Tue, Jan 11, 2011 at 4:57 AM, Sean Murphymhysnm1...@gmail.com wrote: Hi all. I have read the explaination of the Map function and it is still a mystry to myself on what it is for and when would you use it? All explainations I have seen in books and blogs don't make it

Re: problems hashing

2011-01-06 Thread John W. Krahn
Chris Stinemetz wrote: Hello all, Hello, I am having problems using hash function. I would like to only extract 4 columns of data from a text file that is ; delimited. Below is my code along with the errors I am receiving. Any help is appreciated. -Chris 1. #!/usr/bin/perl 2.

Re: Filesys::SmbClientParser Issue

2010-12-30 Thread John W. Krahn
Anand Parthiban wrote: Dear Team, Hello, I have a Issue while using Filesys::SmbClientParser Below is my code : #!/usr/bin/perl use Filesys::SmbClientParser ; $smb = new Filesys::SmbClientParser(undef, (user = $input_hash{DMS_USER}, password = $input_hash{DMS_PASS})); $path =

Re: Extract matched pattern into array

2010-12-20 Thread John W. Krahn
Brian Fraser wrote: Well, what have you tried? And what exactly do you want to store for each line? If you want to get a data structure that looks something like line number = {Equation = 1, Spec = 2, Timing = 1}, then an ugly way would be use strict; use warnings; use 5.010; use

<    1   2   3   4   5   6   7   8   9   10   >