Re: Patching a binary file

2010-05-09 Thread John W. Krahn
Chap Harrison wrote: Hi, Hello, I need to search a binary file using a regex, and replace a 20-byte string with another 20-byte string (binary). The FAQ talks about "perl -pi -e 's/foo/bar/g' myfile", but given that I'm dealing with binary, and that I want to do this from within a larger

Re: why this open/print not work?

2010-05-08 Thread John W. Krahn
Xiao Lan (??) wrote: # cat t1.pl use strict; use warnings; my $cfg = "1.txt"; my @x = qw/a b c 1 2 3/; my $fd; open $fd,">",$cfg or die $!; print $fd for @x; Perl doesn't know that $fd is a filehandle and so it thinks you mean: print STDOUT $fd for @x; Just remove the foreach statement modi

Re: how to arrange a default action in a dispatch table

2010-05-08 Thread John W. Krahn
Harry Putnam wrote: I'd like to be able to use the Lettered choices with a number too, but see no way other than taking user input at those choices. Is there a way to input NUMBER LETTER where the Number is not known in advance? In the example here... I've just taken more user input at the Lett

Re: how to arrange a default action in a dispatch table

2010-05-08 Thread John W. Krahn
Harry Putnam wrote: Philip Potter writes: I was asking, not suggesting one over the other. Â And was not offering an opinion on it don't now enough. You've trimmed the context I was referring to. But you said: But there are no trailing new lines.. guaranteed by: [example snipped] which

Re: how to arrange a default action in a dispatch table

2010-05-07 Thread John W. Krahn
Harry Putnam wrote: Summary: How to arrange for a default action in a dispatch table, along with several single Letter choics and numeric choices. Details: This script is a mock up of something I'm trying to do, and is way pared down from a much larger script... mostly its the dispatch table I

Re: logic not being able to score last element in the array

2010-05-05 Thread John W. Krahn
iinfer wrote: Hi, Hello, I'm new to perl but very enthusiastic about it. I'm having an issue with the following code. The task: two arrays one with a key "key" and one with responses from a form "responses". The idea is that each value in the responses array will be compared to key; if the

Re: Array, foreach problem

2010-05-05 Thread John W. Krahn
Akhthar Parvez K wrote: On Wednesday 05 May 2010, Shawn H Corey wrote: Brian wrote: foreach $line () { while (my $line = <$logfile>) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thin

Re: Teaching Perl

2010-05-03 Thread John W. Krahn
Samuel Williams wrote: Dear Friends, Hello, It would also be great if someone could rewrite the Perl source code example so that it is as close as possible to the C implementation: http://programming.dojo.net.nz/languages/c/index /* Include the standard input / output functions *

Re: Still pondering working with hashs

2010-05-02 Thread John W. Krahn
Harry Putnam wrote: my %h1 = ( './b/f1' => 'f1', './b/c/fa' => 'fa', './b/l/c/f2' => 'f2', './b/g/f/r/fb' => 'fb' ); my %h2 = ( './b/fb'=> 'fb', './b/c/fd' => 'fd', './b

Re: Creating groups of bat files from perl script

2010-04-30 Thread John W. Krahn
Paul wrote: OK, was kinda rust, been working on Solaris servers for year, but not been working solely with windows, but I sure do miss scripting, no matter how screwed up my programming skills are, it's fun! Here is what I have with "\" replacing "/" and better fixes with counting. Yes, I know

Re: Here Docs

2010-04-30 Thread John W. Krahn
Jim Gibson wrote: On 4/30/10 Fri Apr 30, 2010 9:27 AM, "Joseph L. Casale" scribbled: Inside a here doc, how can I force an expression to be evaluated such as localtime: print <<"END"; `localtime time` Foo Bar END I know I can simply create the var before, my $var = localtime time; Bu

Re: matching values of one hash to another

2010-04-29 Thread John W. Krahn
Harry Putnam wrote: I posted my effort at digging out the matches. I see the way you did it, even though not the exact results I was after is 100s of percent better way to write it. I'm curious though if the overhead is different in your compact code compared to mine. That is, if all that

Re: function return

2010-04-29 Thread John W. Krahn
Akhthar Parvez K wrote: On Thursday 29 Apr 2010, Shlomi Fish wrote: Why are you assigning to variables inside @_? It's almost always a bad idea. @_ is the function parameters' list. You should read the values from there (using "my ($param1, $param2, $param3) = @_;" or "my $param1 = shift;" (sh

Re: function return

2010-04-29 Thread John W. Krahn
Akhthar Parvez K wrote: Hi, Hello, The following line stores the first return value by the function Function1 to the variable $name: my ($name) = @_[0] = &Function1 ($arg); The array slice @_[0] forces list context on the right side of the assignment but warns. $name in parentheses forc

Re: matching values of one hash to another

2010-04-28 Thread John W. Krahn
Harry Putnam wrote: I need to do some matching of filenames in two top level directories. We expect to find a number of cases where the endnames ($_) are the same in both hierarchies but the full name is different. base1/my/file base2/my/different_path/file I've made hashes of the file nam

Re: sendmail arguments

2010-04-28 Thread John W. Krahn
John Bruin wrote: I have inherited a Perl script which sends and parses email. I am having trouble trying to figure out what the "-oi" and "-oem" arguments do in the sub below. Can anyone help? They are arguments for the program in $sendmail. First you have to find out what $sendmail contains

Re: Interactive shell in Perl

2010-04-28 Thread John W. Krahn
Parag Kalra wrote: Hey All, Hello, Wanted to know if Perl has any interactive shell (just like Python, Bash, Ruby etc have) by any chance. And if yes how do we invoke that. perldoc -q "Is there a Perl shell" John -- The programmer is fighting against the two most destructive forces in the

Re: Reg Exp: Extract from last appearance of A to first appearance B

2010-04-27 Thread John W. Krahn
HolyNoob wrote: Hi, Hello, I'm trying to make a regexp to match the last appearance of a word (lets say 'abc') until the first appearance of another word (for ex: 'xyz'), and I still cannot do it. For example: with a string like this "abc abc abc toto toto xyz xyz xyz" , which regexp I have

Re: Perl rounding errors?

2010-04-26 Thread John W. Krahn
Rob Coops wrote: Thank you all that replied, in the end I copied the rules I learned in elementary school about how to round a number to two decimals. I'm sure it is a horrible hack and can be done a lot faster, but with a country not being able to process their invoices into the accounting syst

Re: special variable $? usage

2010-04-24 Thread John W. Krahn
Shawn H Corey wrote: Brandon McCaig wrote: my $cmdline = "echo 'DIS CHS(*)' | runmqsc SQFR | grep CHANNEL | sort | uniq -c"; # Open input pipe from command line. open(my $pipe, "-|", $cmdline); open my $pipe, '-|', $cmdline or die "could not open pipe: $!\n"; for my $line (<$pipe>) whil

Re: special variable $? usage

2010-04-22 Thread John W. Krahn
Bruno Costacurta wrote: Hello, Hello, I'm looking about how to work with $? returning from a system call. Have you read the documentation for that variable? perldoc perlvar I have the following : system("echo 'DIS CHS(*)' | runmqsc SQFR | grep CHANNEL | sort | uniq -c"); print $?; whi

Re: while and eval

2010-04-21 Thread John W. Krahn
Arun P Menon wrote: Hello All, Hello, Could you tell me what does the following do? 1 while (<>); That reads through all the files listed on the command line, or if there are no files listed on the command line then it reads through STDIN, and does nothing with the lines read, but does se

Re: Why is the answer right...

2010-04-19 Thread John W. Krahn
Harry Putnam wrote: "John W. Krahn" writes: [...] The main problem is that you are not testing edge cases like: ev 101201 3 Or: ev 100101 3 If you did you would get an error message like: Month '12' out of range 0..11 at Why_is_the_answer_right.pl line 74

Re: Why is the answer right...

2010-04-18 Thread John W. Krahn
Harry Putnam wrote: I may have turned the question around from the usual approach, but I'm having trouble seeing why my script gives the right answer. The script reads data that contains dates in the format YYMMDD N, the N isn't part of the date but is also a digit. What the script tries to do

Re: Extract substring from offset to space or full stop

2010-04-18 Thread John W. Krahn
Mimi Cafe wrote: From: John W. Krahn [mailto:jwkr...@shaw.ca] Mimi Cafe wrote: I used MySQL substr function to extra 100 characters from the result of a query, but understandably, I don't get what I want. Now I looked at Perl's substr function and it doesn't look like

Re: Extract substring from offset to space or full stop

2010-04-18 Thread John W. Krahn
Mimi Cafe wrote: I used MySQL substr function to extra 100 characters from the result of a query, but understandably, I don't get what I want. Now I looked at Perl's substr function and it doesn't look like it can help me achieve what I need to. Let's say I have: $s = "The black cat climbed th

Re: How to properly fold a subject header in email

2010-04-18 Thread John W. Krahn
Harry Putnam wrote: "John W. Krahn" writes: [...] From: http://www.rfc-editor.org/rfc/rfc5322.txt 2.2. Header Fields [...] (and even within some of the lexical tokens), folding SHOULD be limited to placing the CRLF at higher-level syntactic breaks. For

Re: How to properly fold a subject header in email

2010-04-17 Thread John W. Krahn
Harry Putnam wrote: I've acquired a massive headache from trying to look thru some of the mail related modules on cpan that where my searches on header folding lead me. Needless to say I was a little overcome by the attempt. I'm working on my own little home boy perl script that looks through a

Re: about split and \d or . (.)

2010-04-13 Thread John W. Krahn
Hack, Gabi (ext) wrote: Shawn H Corey writes: if ( my ( $year, $mnth, $mday, $extra ) = $_ =~ m{ \A \s* ev \s* (\d\d)(\d\d)(\d\d) \s* (\d+)? \s* \Z }msx ) { just a little side question. i would have written (\d*) Returns the empty string "" if not found. instead of (\d+)? Re

Re: String length limits?

2010-04-12 Thread John W. Krahn
Owen wrote: On Mon, 12 Apr 2010 13:52:16 +0200 Rene Schickbauer wrote: Perl has no string length limit. You are only limited by the amount of memory that is available. If your program is misbehaving then I fear it is the programs error (or well the person that wrote it ;-) rather then perl o

Re: html print

2010-04-12 Thread John W. Krahn
Shlomi Fish wrote: On Monday 12 Apr 2010 12:06:16 Chris Coggins wrote: print < You should always say <<"STOPHTML" <<'STOPHTML' <<`STOPHTML` etc. with explicit quotes depending on what you say. Otherwise, you may not be sure that it's doing the right thing (nor will your readers). As a rea

Re: about split and \d or . (.)

2010-04-11 Thread John W. Krahn
Harry Putnam wrote: What I'm working on will eventually be a script that reads an `events' file and lets me know about events I've entered there. It's my own primitive but hopefully effective calendar reminder type of tool. The format of entries look like this: cat ~/.events ev 100411 4

Re: Subroutine doesn't write to file

2010-04-11 Thread John W. Krahn
Abimael Martinez wrote: Hi, Hello, I am having some problems making this little script work, it is supposed glob files from current dir, and add stuff at the top and bottom of such files. I am also unshure how the "autoflush" works. use strict; use IO::File; use IO::Handle qw( ); my @

Re: about split and \d or . (.)

2010-04-11 Thread John W. Krahn
Uri Guttman wrote: "HP" == Harry Putnam writes: HP> elems1 ( `split(/(\d\d)/,100421)' ): HP> has these elements: HP> I'm an element -> <> that is because there is always a leading null string between the start ITYM: almost always and a leading deli

Re: about split and \d or . (.)

2010-04-11 Thread John W. Krahn
Alan Haggai Alavi wrote: On 11 April 2010 21:10, Harry Putnam wrote: Why is it that the first two splits do not produce any elements? #!/usr/local/bin/perl use strict; use warnings; my $var = 100421; my @elems1 = split(/\d/,$var); my @elems2 = split(/./,$var); my @elems3 = split(//,$var);

Re: about split and \d or . (.)

2010-04-11 Thread John W. Krahn
Harry Putnam wrote: Why is it that the first two splits do not produce any elements? Because: perldoc -f split split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split Splits the string EXPR into a list of strings and returns that list. By default,

Re: run Unix commands from script!

2010-04-09 Thread John W. Krahn
Niko zuna wrote: Hi! Hello, I made this short script in order to see if there is posible to run "modified" unix commands from a Perl script. #!/usr/bin/perl use strict; use warnings; my $load = `uptime | awk '{print $8 $9 $10 $11 $12}'`; my ( $load ) = `uptime` =~ /(load average: .+)/;

Re: Decimal representation of binary file (unpack)

2010-04-08 Thread John W. Krahn
Philip Potter wrote: On 8 April 2010 06:30, Raymond Wan wrote: I would like to read in a binary file and extract the 4-byte ints from it. Under Linux, something like "od -t uI". I got it working as follows: my $buffer = ; my @buffer = split //, $buffer; for (my $i = 0; $i < length ($buffer

Re: Permission mode of a directory

2010-04-05 Thread John W. Krahn
Dr.Ruud wrote: Akhthar Parvez K wrote: Didn't know that Perl only deals with decimal numbers. Wherever did you get that idea? I think I might have mentioned that. :-) John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity.

Re: Permission mode of a directory

2010-04-03 Thread John W. Krahn
Akhthar Parvez K wrote: Hi all, Hello, I have been trying to get the mode of a directory with the stat function in perl (currently using the one from File::stat) with no success so far. It looks like it is working to me. Basically I want to check if a given directory is having 1777 permis

Re: function umask() and problem in GD::image->png

2010-03-31 Thread John W. Krahn
CHAN, KENNETH 1 [AG/7721] wrote: Hi all, Hello, I have 2 simple questions (maybe be very trial): 1. I saw some code put "umask 022;" in the near beginning of perl script. I understand that umask is for changing the file permission in unix/linux. No, that is incorrect. umask() by itself d

Re: Ternary operator: Am I missing something?

2010-03-29 Thread John W. Krahn
Jeff Peng wrote: On Mon, Mar 29, 2010 at 10:02 PM, Jeff Soules wrote: Am I missing something? I have the following chunks of code: EX 1: if ($foo == 1){ $bar = 0; }else{ $bar = 1; } EX 2: ($foo == 1) ? $bar = 0 : $bar = 1; Th

Re: Ternary operator: Am I missing something?

2010-03-29 Thread John W. Krahn
Jeff Soules wrote: Hi all, Hello, Am I missing something? Precedence. perldoc perlop I have the following chunks of code: EX 1: if ($foo == 1){ $bar = 0; }else{ $bar = 1; } EX 2: ($foo == 1) ? $bar = 0 : $bar = 1; These are logically eq

Re: Perl: hashes of arrays!

2010-03-26 Thread John W. Krahn
alekto wrote: Hi, Hello, I got this script that is executed like this: ./colstat.pl -f -e ; (specifywhat to use in the split function in order to divide the columns) I would like to put each line from the input file into an array, and I want to put this array into a hash, where the column nu

Re: $_ substitution Question

2010-03-26 Thread John W. Krahn
John W. Krahn wrote: jet speed wrote: I have a simple code below, ### #!/usr/bin/perl use strict; use warnings; my @list =( '/usr/data/logs' , '/usr/data1/logs'); foreach (@list) { print "$_ \n"; system "(/usr/bin

Re: $_ substitution Question

2010-03-26 Thread John W. Krahn
jet speed wrote: Hi, Hello, I have a simple code below, ### #!/usr/bin/perl use strict; use warnings; my @list =( '/usr/data/logs' , '/usr/data1/logs'); foreach (@list) { print "$_ \n"; system "(/usr/bin/find "$_" -mtime 3 -print -exec ls '{}' \;)"; } #

Re: reutun undef

2010-03-24 Thread John W. Krahn
Jeff Peng wrote: "return" statement with explicit "undef" at line 185, column 9. See page 199 of PBP. (Severity: 5) I got the cpan test report, it pointed out the one above. Is "return undef" not to be encouraged in current Perl? Only if you want to explicitly return a single scalar value

Re: detect disk full when write to handle

2010-03-20 Thread John W. Krahn
C.DeRykus wrote: On Mar 19, 8:31 pm, godsarm...@gmail.com (Walt Chen) wrote: I have a public disk partition shared by different users. Everyone on the host writes different temporary file from time to time. So the partition runs out of available disk space sometimes. I have a perl script to wr

Re: quick question

2010-03-19 Thread John W. Krahn
Chris Knipe wrote: Hi, Hello, I was just wondering, when we talk about integers specifically, Why integers specifically? The same applies for any scalar value. what's the difference between: my $foo = 1; my $bar = 1; and my ($foo, $bar) = 1 I am getting more and more occurances where

Re: no lstat happens

2010-03-17 Thread John W. Krahn
Harry Putnam wrote: I've finally gone on around the bend, I guess... I'm not seeing why the script below <./t2> doesn't show the value of $mode when fed by the ls cmd shown: (first, to shows whats here) ls -l *[eo2] -rw-r--r--+ 1 reader reader 5 Mar 16 15:26 one -rwxr-xr-x+ 1 reader re

Re: getting input without hitting return

2010-03-17 Thread John W. Krahn
Greg wrote: Hi everybody, Hello, I have a script, where a user can choose between different options (add user (U), add item (I), search (S)). I want the user to hit either U, I or S. However, right now, he needs to hit return as well. Is there a way to get input without hitting return? pe

Re: Freeing Memory

2010-03-17 Thread John W. Krahn
hsfrey wrote: I have a big data file - about 7000 entries, each about 100 bytes. 700,000 bytes is *not* a big file these days. I have to search it on the order of 7000 times, so I need to keep it in memory. As I search, some items no longer need to be searched, but they still need to be sav

Re: Replacement in 3GB file

2010-03-15 Thread John W. Krahn
Ganesh Babu N wrote: Dear All, I am using the following code to replace certain information in binary mode. Did you not like the answers you got from perlmonks.org? John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity.

Re: would like "pure" Perl solution to count of files in directory (nested subdirectories too)

2010-03-14 Thread John W. Krahn
Kenneth Wolcott wrote: Hi; Hello, Re: would like "pure" Perl solution to count of files in directory (nested subdirectories too) I would like to have a "pure" Perl solution to "find dir | wc -l" perl -MFile::Find -le'find sub { ++$count }, "dir"; print $count' John -- The programmer is

Re: Read line by line from a file & search each line on another file

2010-03-13 Thread John W. Krahn
manu wrote: Want to do a perl program - Read from file 1 - line1, line2etc Search line1 on file2 (all lines) Then Search line 2 on file 2... Ouput results of search. perldoc -q "How can I read in an entire file all at once" perldoc -q "How do I efficiently match many regular expressions

Re: assign s/// value to a scalar

2010-03-11 Thread John W. Krahn
raphael() wrote: #!/usr/bin/env perl use strict; use warnings; my @array = qw ( http://abc.com/files/randomthings/A/1.html http://abc.com/files/randomthings/A/2.html ); for ( @array ) { # This works # s!/A/\d+.html$!!; $url = $_; Not quite, that should be: s!/A/\d+\.html$!!; $url

Re: why on while?

2010-03-11 Thread John W. Krahn
Shawn H Corey wrote: Dr.Ruud wrote: Jeff Peng wrote: so how about while (my $line = ) instead of using $_? Evil! An empty line, or a line with only a "0" in it. Not quite. Lines are not completely empty. A blank line would have "\n". A line with just zero would have "0\n". Only after a

Re: why on while?

2010-03-11 Thread John W. Krahn
Dr.Ruud wrote: Jeff Peng wrote: so how about while (my $line = ) instead of using $_? Evil! An empty line, or a line with only a "0" in it. Evil? "while (my $line = )" is *exactly* the same as "while (defined(my $line = ))" $ perl -e' my $x = 1; my $data = "one\ntwo\nthree\n0"; open FH,

Re: Reading BInary file.

2010-03-09 Thread John W. Krahn
John W. Krahn wrote: jis wrote: Hello Perl Gurus. Hello, I have been trying to read BInary file and have not found the best way to parse it through. I have been through perl forums and have not found a statisfactory answer. Iam trying to read binary file (.bin) and read it to an array in

Re: Mass value assigment

2010-03-09 Thread John W. Krahn
Shlomi Fish wrote: On Monday 08 Mar 2010 18:00:10 Ryan Chan wrote: my ($a, $b, $c, $d, $e) = "test"; How I can assign "test" to all the list items? e.g. $a to $e First of all, you should not name lexical variables "$a" and "$b" because these are built-in Perl variables: http://perldoc.perl.o

Re: Reading BInary file.

2010-03-09 Thread John W. Krahn
jis wrote: Hello Perl Gurus. Hello, I have been trying to read BInary file and have not found the best way to parse it through. I have been through perl forums and have not found a statisfactory answer. Iam trying to read binary file (.bin) and read it to an array in hex format bytewise. I

Re: tr// versus s///g

2010-03-08 Thread John W. Krahn
Tony Esposito wrote: On Mon, 8/3/10, John W. Krahn wrote: Tony Esposito wrote: Does tr/'\n'/' '/ Replace every ' with ' and every "\n" with " " and every ' with '. Should probably just be tr/\n/ /. do the same as tr/'\n&#

Re: good practice in File::Find

2010-03-08 Thread John W. Krahn
Harry Putnam wrote: I want to know if doing something like what is in the code below would be expensive or for some other reason a bad choice. There is more code, that either feeds the `find()' function or further processes the results of the `find()' part. The code is not in finished form, or

Re: tr// versus s///g

2010-03-08 Thread John W. Krahn
Tony Esposito wrote: Does tr/'\n'/' '/ Replace every ' with ' and every "\n" with " " and every ' with '. Should probably just be tr/\n/ /. do the same as tr/'\n'/' '/g? I assume you mean s/'\n'/' '/g because /g is not a valid option for tr///. That will replace the string "'\n'" with

Re: parsing numbers from grep

2010-03-03 Thread John W. Krahn
Shawn H Corey wrote: Uri Guttman wrote: that modifies @ARGV so it is a bad idea. also it bypasses grep's purpose of filtering a list. and as i posted, map is the correct solution map is not the correct solution since it does not filter out those which do not match the pattern. Only grep can d

Re: mech->content match regex howto

2010-03-02 Thread John W. Krahn
raphael() wrote: Cool! I have to admit that is a "detailed" answer. Also thanks for clearing out the differences between these two.. ( my $ip = $last_page ) =~ m/([\d+\.]+)/; ( my $ip ) = ( $last_page ) =~ m/([\d+\.]+)/; Just to clear out any misunderstanding "by above one" I meant ( my $ip =

Re: mech->content match regex howto

2010-03-01 Thread John W. Krahn
raphael() wrote: Hi, Hello, I am trying to understand WWW::Mechanize Did you also look at these pages: http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize/Examples.pod http://search.cpan.org/~petdance/WWW-Mechanize-1.60/lib/WWW/Mechanize/FAQ.pod http://search.cpan.org/~pe

Re: Inserting a pause into a loop

2010-02-24 Thread John W. Krahn
Erik Lewis wrote: Hi, Hello, I'm writing a perl script thats goal is to read a delimited file containing a userid and an address to google maps where the address is converted into latitude and longitude. The problem I'm having is with the result I'm printing. Each line is unique via the use

Re: create user from csv

2010-02-22 Thread John W. Krahn
akabou wrote: Hello, everybody Bonsoir, I have a csv file with firstname, lastname, group and need to create user and group if it doesn't exist. But the problem is that i must not use useradd ou groupadd. That way lies madness. If you do not intend to use the tools provided then how do

Re: octal?!

2010-02-21 Thread John W. Krahn
Bryan R Harris wrote: John W. Krahn wrote: Bryan R Harris wrote: "print+(eval)[-1]"??? What's the "+" for? You're amazing, John. The "+" is so that you don't get a syntax error because "print(eval)" with "[-1]" after it is

Re: octal?!

2010-02-20 Thread John W. Krahn
Bryan R Harris wrote: Bryan R Harris wrote: This is unintuitive: perl -e 'print "> "; while(<>) {print(( eval $_ )[-1], "\n> ")}' ... then enter 2*012. It prints "20". 2*12 is obviously 24, but perl's interpreting that "012" as octal. We sometimes have our numbers zero padded to make th

Re: octal?!

2010-02-19 Thread John W. Krahn
Bryan R Harris wrote: This is unintuitive: perl -e 'print "> "; while(<>) {print(( eval $_ )[-1], "\n> ")}' ... then enter 2*012. It prints "20". 2*12 is obviously 24, but perl's interpreting that "012" as octal. We sometimes have our numbers zero padded to make the columns line up, they'

Re: how do I replace all the spaces in a string with +

2010-02-19 Thread John W. Krahn
Sergey Matveev wrote: Greetings, On Fri, Feb 19, 2010 at 03:54:27PM -0500, Erik Lewis wrote: I have to changes all the spaces in a string to +'s. Is there an easy way to do this. The length of the string and the number of spaces will always be changing. $string =~ s/ /\+/g; That is all.

Re: Reading file from web into a hash

2010-02-16 Thread John W. Krahn
Herb wrote: Hi All, Hello, I am a perl novice and am having some trouble with formatting a web file to put into a hash. I have the following code: #!/usr/bin/perl -w use LWP::Simple; #use strict; sub sws { my $file = shift; You should probably pass the filehandle instead of the

Re: Perl script writes another script, which characters to escape

2010-02-14 Thread John W. Krahn
Chris Coggins wrote: I'm using a perl script to write another perl script that will be executed later. I need to know if all the characters that need to be escaped, are properly escaped. Can someone help, here's a portion of the code below. Are all the characters properly escaped? (note this is

Re: file handling

2010-02-12 Thread John W. Krahn
elavazhagan perl wrote: Yes, you are absolutely right.. We need to increment the line by one and field ID by 20. Whatever my be the fied id.. Thanks, OK, I give up. Does anyone else want to try eliciting a cogent and informative response? John -- The programmer is fighting against the two

Re: file handling

2010-02-12 Thread John W. Krahn
elavazhagan perl wrote: Hope,this time I will make you clear. Our script converts the original content to current output ,what we need is the desired output. So I take it by "line" you actually mean "Field record"? *ORIGINAL CONTENT:*

Re: file handling

2010-02-11 Thread John W. Krahn
elavazhagan perl wrote: On 2/11/10, John W. Krahn wrote: elavazhagan perl wrote: I have a program which reads the input file,updates once and outputs in a new file. Ex.The first line L1 will be updated to L2. I need to put this into a loop so that the scripts will be invoked 1000 times and

Re: file handling

2010-02-11 Thread John W. Krahn
elavazhagan perl wrote: Hi, Hello, I have a program which reads the input file,updates once and outputs in a new file. Ex.The first line L1 will be updated to L2. I need to put this into a loop so that the scripts will be invoked 1000 times and the output contains the appended data(L1 TO L10

Re: More basic questions

2010-02-10 Thread John W. Krahn
PolyPusher wrote: All, Hello, I have a file that defines pins for an IC. The code needs to find ".SUBCKT RE1321_4" and produce a list that complies with SKILL(lisp) context for Cadence tool suite, the output needs to like ("Ant" "DCS_RX".. "last pin ") and outputs to a file... If pin

Re: 1-line text file with numbers, need to add to them

2010-02-05 Thread John W. Krahn
Frank wrote: On Feb 4, 4:35 pm, jwkr...@shaw.ca ("John W. Krahn") wrote: Chris wrote: I need some help with this problem. I've got a text file datafile with 1 line of data comprised of 30 different numbers delimited with ~s. I need to open this file, grab this line of data

Re: complex subroutine arguments

2010-02-04 Thread John W. Krahn
Eric Mooshagian wrote: On Thu, Feb 4, 2010 at 2:24 AM, John W. Krahn wrote: Eric Mooshagian wrote: I have a few subroutines that I use to first build an index for several arrays and then, for example, take the mean for the index values. When I build the index I can exclude particular

Re: 1-line text file with numbers, need to add to them

2010-02-04 Thread John W. Krahn
Chris wrote: I need some help with this problem. I've got a text file datafile with 1 line of data comprised of 30 different numbers delimited with ~s. I need to open this file, grab this line of data, split it into individual numbers, perform some simple math (addition) on each number, and then

Re: complex subroutine arguments

2010-02-03 Thread John W. Krahn
Eric Mooshagian wrote: Dear All, Hello, I have a few subroutines that I use to first build an index for several arrays and then, for example, take the mean for the index values. When I build the index I can exclude particular values in an array as follows: my $index = defindex( exclud

Re: Basic Perl Questions

2010-02-03 Thread John W. Krahn
PolyPusher wrote: Hi All, Hello, I have some Perl experience but has been awhile. I mainly write SKILL lisp programs for Cadence CAD for a layout group(we are a IC design center). I have a CBR(describes circuit) file and want to open it, find the line in file Is it just one line or are t

Re: newline problem

2010-02-01 Thread John W. Krahn
Michom wrote: HI, Hello, I am new to perl and I have written a smal script to grab data from one file, and put them into another file. The problem is new lines, which are printing nice under a linux environment, but it is all messed up if I open it with notepad. I am running Perl 5 under cygw

Re: Warning: Use of uninitialized value

2010-01-30 Thread John W. Krahn
[ Please do not top post. ] 7 wrote: a) open (BHF_FILE, " The modern way to open a file is to: 1) Use the three argument form of open(). 2) Create a variable for the file handle. open (my $BHF_FILE, '<', '/home/bob/tmp/md4music'); You should *always* verify that the file was opened correct

Re: Warning: Use of uninitialized value

2010-01-28 Thread John W. Krahn
Bob Williams wrote: Hi, Hello, I am trying to split the lines in a file into two halves (at the first space) each half going into an array. The code I have written is below. The print command is there to test that things worked correctly, but it only gives an error for each instance of the

Re: how to get only error/warnning messages from a file

2010-01-27 Thread John W. Krahn
V U Maheswara rao k wrote: Thanks Jhon, my search string may be more than 100 words like ("warnings", "errors", "Caution","Debug","notice","info"..etc). so that I want to get it from array and search it in each line I want to search a list in a line of file. perldoc -q "How do I efficiently m

Re: how to get only error/warnning messages from a file

2010-01-27 Thread John W. Krahn
V U Maheswara rao k wrote: HI , Hello, I have to get only error messages and warnings text form "/var/log/messages". I wrote below code for to get only "warnings, error and caution " messages from a file. but grep command wont work. because I have to pass scalar variable to search. #!/usr/b

Re: ARGV behaviour in getopts std

2010-01-23 Thread John W. Krahn
Harry Putnam wrote: This is probably blindingly simple but I'm not understanding why @ARGV is not reduced to () (no args)? in this example [ SNIP ] print "Now lets ditch the rest in a for loop\n"; for (@ARGV){ my $ditch = shift; perldoc perlsyn [ SNIP ] Foreach Loops [ SNIP ] Th

Re: need some help excluding with file::find::rule

2010-01-22 Thread John W. Krahn
solaristar wrote: First please forgive me if this is the wrong way to go about asking this question. I already answered this question on comp.lang.perl.misc. Do you want me to answer it again here? John -- The programmer is fighting against the two most destructive forces in the universe:

Re: regex support for glob

2010-01-20 Thread John W. Krahn
Parag Kalra wrote: On Wed, Jan 20, 2010 at 2:20 PM, Shameem Ahamed wrote: I am wondering how can i use the glob function to get only the first few files. I have files with digits as extensions. Like file.0, file.1 file.2..file.100,file.101 etc. I want to select only the first 30 files.

Re: Data file with records that span two lines

2010-01-19 Thread John W. Krahn
Perl Noob wrote: I have a data file with thousands of records. The problem is that the records in the data file span two lines for each record. I want to write a perl script that makes each record a single line. The file looks like this: RECORD1FIELD1 RECORD1FIELD2 RECORD1FIELD3 RECORD1

Re: Queries - Newbie

2010-01-13 Thread John W. Krahn
dolphin wrote: Hi, Hello, I want to use perl and print time before and after sleep but not successful, can anyone advice? #!/usr/bin/perl my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime time; my $timenow="$hour$min$sec"; print "It is now $timenow\n"; sleep 15; my $timelat

Re: readline() on unopened filehandle at

2010-01-12 Thread John W. Krahn
Noah wrote: Hi there, Hello, I am trying to figure out why the following error is happening from time to time when I am unlink'ing a file. readline() on unopened filehandle at ./check.pl line 207. here is the code - lines 205-207 my $filename = "$outputdir/$device.$configuration_file_

Re: FTP and LS or DIR

2010-01-07 Thread John W. Krahn
Jag Thripp wrote: Hello first question, maybe one of many! Hello, Code running on a windows machine connecting to Linux box. I am trying to capture an ls\dir command into a file from an FTP connection, similar to ls -lA > Ls.txt. I am trying to monitor files in a folder on a remote Red Hat

Re: paths that work in windows and linux + Umlaute

2010-01-05 Thread John W. Krahn
Andreas Moroder wrote: Hello, Hello, I have found a nice utility http://www.novell.com/communities/node/389/adm+file+utilities+2+5 that has two problems: has *many* problems. 1) It creates directories and files but it uses the \ backslash so it does not work on a linux machine. Is ther

Re: regex optimization

2010-01-05 Thread John W. Krahn
Jeff Peng wrote: Hello, Hello, Can the code (specially the regex) below be optimized to run faster? #!/usr/bin/perl for ($i=0; $i<1000; $i+=1) { ++$i is usually faster than $i+=1. But you are not using the $i variable so you don't really need it (your Ruby programs don't have it.) for

Re: Reference subroutine as parameter

2009-12-30 Thread John W. Krahn
Trevor Vallender wrote: Hi, Hello, I have just moved a piece of code into a separate module. However, the subroutine in the new module needs to reference a subroutine in the script it's called from. Is there any way around this? Basically, I am using AnyEvent::XMPP, and want the setup code i

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