Re: Appending sequential numbers to a file, one number per line

2008-12-29 Thread John W. Krahn
blackd77 wrote: Hello. I want to add sequential numbers to a file, one number per line, at the end of each line. The files have a .csv format. So, I'd like to add ,1 to the first line, ,2 to the second line, and so on (without the quotation marks of course). I have not started building the code,

Re: Appending sequential numbers to a file, one number per line

2008-12-29 Thread John W. Krahn
John W. Krahn wrote: blackd77 wrote: Hello. I want to add sequential numbers to a file, one number per line, at the end of each line. The files have a .csv format. So, I'd like to add ,1 to the first line, ,2 to the second line, and so on (without the quotation marks of course). I have

Re: There is a error in a simple source

2008-12-28 Thread John W. Krahn
emenzhaow...@gmail.com wrote: looks like you missed the closing brace of sub. Incorrect. It is there. John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For

Re: There is a error in a simple source

2008-12-28 Thread John W. Krahn
John W. Krahn wrote: mobile.parmeni...@gmail.com wrote: I'm new to perl. The following code is wrong., and I can not spot it. Any suggestion? Thx. #!/usr/bin/perl -w #!/usr/bin/perl use warnings; use strict; init_words (); init_words(); my %word; sub init_words{ while

Re: Changing some filenames

2008-12-27 Thread John W. Krahn
M.Lewis wrote: I have a need to manipulate some filenames. The files are all in a single directory. They are currently named in the form: 01012003-Rattler.tar.gz 01162003-Rattler.tar.gz 01312003-Rattler.tar.gz 02152003-Rattler.tar.gz These are backup files from a machine. What I will

Re: There is a error in a simple source

2008-12-27 Thread John W. Krahn
mobile.parmeni...@gmail.com wrote: Hi, Hello, I'm new to perl. The following code is wrong., and I can not spot it. Any suggestion? Thx. #!/usr/bin/perl -w #!/usr/bin/perl use warnings; use strict; init_words (); init_words(); my %word; sub init_words{ while (

Re: read line in, print each line to separate file

2008-12-24 Thread John W. Krahn
Charlie Farinella wrote: On Wednesday 24 December 2008, Mr. Shawn H. Corey wrote: On Wed, 2008-12-24 at 13:16 -0500, Charlie Farinella wrote: I need to read in a file of 200 lines and print each out to a separate file. I've been stumbling with this, but I don't know how to name each outfile

Re: using (dot) . with printf does not incur the results I expected

2008-12-24 Thread John W. Krahn
Richard wrote: what's wrong w/ this ? I used (dot) . to indicate the maximum length of each element in the print but last one does not print out in alinged format.. What am i missing? use warnings; use strict; my $yabal = 'truncated'; my $never = 'sai'; my $noway = 'han1'; my %never = qw(hi

Re: What is the proper method for calling a shelll script?

2008-12-23 Thread John W. Krahn
Chas. Owens wrote: On Tue, Dec 23, 2008 at 13:12, Steve Pittman spitt...@jhmi.edu wrote: Does any one have a good example? snip That depends on what you want to do. There are five common ways of executing external programs (including shell scripts): 1. the system function* 2. the qx//

Re: 2 questions please, one on scope and one on regex

2008-12-22 Thread John W. Krahn
Eric Krause wrote: Hello all, Hello, I have two quick questions that I would love some help on. I have looked at the manual (Programming Perl) and I didn't get it, hence my email. Question 1 - How can I make variables in a function (subroutine) global (accessible from other functions)?

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Christopher Yee Mon wrote: I have an array of strings whose members consist of a number followed by a comma followed by a text string e.g. 1,fresh 2,testurl I want to sort by descending numerical order according to the number part so I made this sort subroutine sub by_counter_field {

Re: Sorting an array by a substring of its members

2008-12-15 Thread John W. Krahn
Brian Tillman wrote: I'm probably missing something, but what's wrong with?: sort {$b = $a} @array; Nothing, unless you have, as you really should, warnings enabled: $ perl -le' use warnings; my @array = ( 1,fresh, 2,testurl ); @array = sort { $b = $a } @array; print for @array; ' Argument

Re: Creating a Logon Form

2008-12-14 Thread John W. Krahn
John W. Krahn wrote: PekinSOFT wrote: John W. Krahn wrote: pekins...@gmail.com wrote: I enter the string 'hiyall2008' in the password field and get the following values in my logon script... Click 1: hiyall2008153639492 Click 2: hiyall2008135813700 Click 3

Re: Special characters and variables in search and replace expressions of regexps

2008-12-14 Thread John W. Krahn
Alexei A. Frounze wrote: Here's a sample program to show the problems I'm having with regexps: my $s = a\tb; $s contains a three character string, the 'a' character, the TAB character and the 'b' character. my $m1 = \t; $m1 contains a single TAB character. my $m2 = \\t; # both \t and

Re: data and script in same location, how to write it down

2008-12-14 Thread John W. Krahn
Chas. Owens wrote: On Sun, Dec 14, 2008 at 11:41, Mr. Shawn H. Corey shawnhco...@magma.ca wrote: snip open my $fh, '', $file or die cannot open $file: $!\n; snip Completely off topic, but I dislike the error messages that say cannot. Cannot implies that the problem exists currently and can

Re: Regex pattern match in perl

2008-12-14 Thread John W. Krahn
explor wrote: Hi Gurus, Hello, I am new to perl and need some help to learn regex in perl. From the below line i need to extract following: Part I 1) $ENVFROM = dapi...@testhost.com 2) $ENVTO1 = te...@etc.com 3) $ENVTO2 = te...@etc.com 4) $ENVTO3 = samt...@abc.com line=EnvFrom:

Re: counter program by using closure

2008-12-14 Thread John W. Krahn
Richard wrote: John W. Krahn wrote: You want something more like this: sub counter { my $count; my $clear = `clear`; my $counting = 'EOF'; %s | Counting...| | %2d

Re: counter program by using closure

2008-12-13 Thread John W. Krahn
Richard wrote: wanted to draw a box that's counting up for certain time. Thought I could use the counter but it just displays the box not the number.. can anyone point it out for me? thank you. use warnings; use strict; sub counter { my $count; my $counting = EOF;

Re: Creating a Logon Form

2008-12-12 Thread John W. Krahn
PekinSOFT wrote: John W. Krahn wrote: pekins...@gmail.com wrote: I enter the string 'hiyall2008' in the password field and get the following values in my logon script... Click 1: hiyall2008153639492 Click 2: hiyall2008135813700 Click 3: hiyall2008152312388 et cetera

Re: trying to put in an array patters matched.

2008-12-12 Thread John W. Krahn
ben perl wrote: Hi Hello, I am trying to push values in array to what ever matched in a regular expression. For example $string = something22 322 abc; $string =~ /(\d+)\s(\d+)(abc)/; This should create an array like with elements as (22, 322,abc). my @array = $string =~

Re: understand this regular expression

2008-12-11 Thread John W. Krahn
monnappa appaiah wrote: Hi all, Hello, i have this regex [\x3c][i][m][a][g][e]\x20[s][r][c][=][h][t][t][p][:]\x2f\x2f[\x26][#]114[;][\x26][#]2570[;][\x26][#]114[;][.][b][o][o][k][.][c][o][m] when i tried to put it into human readable form this i got this image

Re: understand this regular expression

2008-12-11 Thread John W. Krahn
monnappa appaiah wrote: Thanks a lot for your quick respone, but can u please tell me how did u know that #114 is 'r' and #2570; is 'GURMUKHI LETTER UU'.. i wud like to know bcoz i wud be dealing with these kind of regex often so it wud be helpful to understand? It might also help if you

Re: Creating a Logon Form

2008-12-10 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hey All, Hello, I'm new to doing CGI with Perl and so am a little lost here. I'm working on a web-accessible database system for a (rather large) group of area churches and went through the rigmarole of assessing various programming and scripting languages to see

Re: Help with String/Array manipulation

2008-12-09 Thread John W. Krahn
sanju.shah wrote: I am looking for some suggestions on any advanced functions Perl might have that i might be missing. Basically, I have an array with column widths. Next I have a string. I would like to extract the number of characters based on the column- widths in the array. I have already

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
David Shere wrote: Hello. Hello, I'm not a new perl programmer, but I feel like one today. I want to pull the last octet off of an IP address and print it to standard output. I have this so far: @octets = split(/\./, $ipAddress); print pop(@octets); Which works great. I have no

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: Mr. Shawn H. Corey wrote: print '', (split( /\./, $ipAddress ))[-1]; Ugly, ugly, ugly. OK, try: print substr($ipAddress,rindex($ipAddress,'.')+1); $ perl -le' my $ipAddress = 23.34.45.56; print $ipAddress =~

Re: Split not acting the way I want it to

2008-12-09 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Wed, 2008-12-10 at 03:04 +, Rob Dixon wrote: Mr. Shawn H. Corey wrote: print '', (split( /\./, $ipAddress ))[-1]; Ugly, ugly, ugly. OK, try: print substr($ipAddress,rindex($ipAddress,'.')+1); $ perl -le' use Socket; my $ipAddress = 23.34.45.56; print

Re: Cannot open file to read after creation

2008-12-03 Thread John W. Krahn
[EMAIL PROTECTED] wrote: I am working on a script to help find malicious traffic that takes the supplied ip and port from the user, does a number of checks (reverse dns, whois, banner grabbing, amap and nmap service fingerprinting), and then prints the results to a file. My intent is to

Re: Cannot open file to read after creation

2008-12-03 Thread John W. Krahn
' is output from nmap: sub nmap { if ( grep /\birc\b/, qx/nmap -sV -P0 -T4 -p $port $ip/ ) { irc(); } } On Dec 3, 2008 7:53pm, John W. Krahn [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I am working on a script to help find malicious traffic that takes the supplied

Re: Reading Files across directories and subdirectories

2008-12-02 Thread John W. Krahn
James Moser wrote: On Dec 2, 2008, at 5:48 AM, Koti wrote: I have a directory named X which has many sub directories Y,Z,W and many files about 20 , and these sub directories also contain some more sub directories and files in them and those sub directories also contain more directories and

Re: converting while loop to a for loop

2008-12-01 Thread John W. Krahn
dippa wrote: basic perl problem which is annoying me, the code is: --- #!/usr/bin/perl -w use strict; my $string; my $subString; my @indexes; print Enter a string:\n; chomp($string = STDIN); print \nEnter substring to search for:\n; chomp($subString = STDIN); ## This while loop does what

Re: df -mg system() - $variable

2008-12-01 Thread John W. Krahn
David wrote: Thank you to all who helped me get a 6 digit date into perl. I certainly heed warnings about not using outside system calls in perl however, I have to make an outside call again. #!/usr/bin/perl -w use strict; my $fileName = 081201 diskSpace.txt; my $fileLoc =

Re: help with subroutines and reading/writing to file

2008-11-30 Thread John W. Krahn
blake askew wrote: I am new to perl and attempting to write a script that will do a reverse dns lookup on an ip, store this result into a file, then read the file in order to do a whois lookup. The whois lookup answer should also be written to a seperate file. I have the reverse dns lookup

Re: Not getting all the element.

2008-11-29 Thread John W. Krahn
slow_leaner wrote: Hello all, Hello, what am i missing!!! #!/usr/bin/perl -w @array_number =STDIN; @new_array = half( @array_number ); print @new_array\n; sub half { @numbers = @_; while (@numbers){ That is short for: while ( defined( $_ = glob join $, @numbers ) ) {

Re: system - $variable

2008-11-29 Thread John W. Krahn
David wrote: I am trying to get 081129 into $dayStamp. #!/usr/bin/perl -w use strict; my $dayStamp; $dayStamp = `date +\'%y%m%d\'` die Failure!; You have three problems with that statement: 1) The '=' operator has higher precedence than the '' operator so you need to either enclose the

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread John W. Krahn
Yimin Rong wrote: wget -q -O - http://random.org/integers/? num=8min=33max=126col=8base=16format=plainrnd=new | perl -ne 'foreach (split(/\t/, $_)) {print chr(hex($_));} print \n' You can simplify the perl part to: perl -lane'print map chr hex, @F' Or just using perl: perl -MLWP::Simple

Re: One liner to generate truly random passwords from command line

2008-11-28 Thread John W. Krahn
Chas. Owens wrote: On Fri, Nov 28, 2008 at 10:28, John W. Krahn [EMAIL PROTECTED] wrote: snip perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' snip Perl Golf time: perl -le'print map chr+(33..126)[rand 94],1..8' $ perl -le'print map chr+(33..126)[rand 94],1..8

Re: print problem when \r is used.

2008-11-26 Thread John W. Krahn
Cathy wrote: my $lines = 0; my $current_line = 0; my $percentage; my $percentage_new; open(my $FILE, , @ARGV[0]) or die Can't open log file: $!; while (sysread $FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } print $lines lines\n; close $FILE or die $in: $!; open(my

Re: global and local confusion

2008-11-25 Thread John W. Krahn
Harry Putnam wrote: John W. Krahn [EMAIL PROTECTED] writes: Harry Putnam wrote: my ($rgx,$use,@finddir); $use = shift @_; $rgx = qr/(^|:)$use /; You are using capturing parentheses but you never use the string thus captured so you may want to use non-capturing parentheses

Re: Uninitialized value in array

2008-11-24 Thread John W. Krahn
sanket vaidya wrote: Hi all, Hello, Kindly look at the code below: my ($bi, $bn, @bchrs); $bi starts out at 0. my $boundry = ; foreach $bn (48..57,65..90,97..122) { $bchrs[$bi++] = chr($bn); $bchrs[ 0 ] is assigned a value and then $bi is incremented to 1. print

Re: how to use perl compare 2 binary files?

2008-11-23 Thread John W. Krahn
loody wrote: Dear all: Hello, I try to use perl to compare 2 binary files, one is display content dump from Dram and another is display content calculated by my c-model code. I use open and binmode to open these 2 files, and use programs as below to do the comparison:

Re: Greedy v non greedy regexps in lookahead.

2008-11-23 Thread John W. Krahn
Andrew wrote: I am tying to expand some camel case with spaces - but I want multiple captitals to remain as one word. So I want PerlNotesOnXML - Perl Notes On XML My attempt is to use [A-Z]+ in a lookahead. my $text = PerlNotesOnXML ; $text =~ s/(?=[A-Z]+)/ /gx ; print $text ; I think

Re: how to read file content into an array?

2008-11-23 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sun, 2008-11-23 at 15:52 +0800, loody wrote: The prototype of read is read FILEHANDLE,SCALAR,LENGTH ex: read PATTERN, $line, 1920; that means the $line will content 1920 bytes. It means it will attempt to read 1920 bytes. The actual number of bytes read is

Re: how to read file content into an array?

2008-11-23 Thread John W. Krahn
loody wrote: 2008/11/23 Chas. Owens [EMAIL PROTECTED]: On Nov 23, 2008, at 2:52, loody [EMAIL PROTECTED] wrote: The prototype of read is read FILEHANDLE,SCALAR,LENGTH ex: read PATTERN, $line, 1920; that means the $line will content 1920 bytes. if I want to modify the byte offset 720 of

Re: how to read file content into an array?

2008-11-23 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sun, 2008-11-23 at 05:34 -0800, John W. Krahn wrote: You shouldn't do something with $line if $bytes_read is undefined: while ( my $bytes_read = read PATTERN, $line, 1920 ) { unless ( defined $bytes_read ) { die error reading $filename

Re: how to read file content into an array?

2008-11-23 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sun, 2008-11-23 at 05:47 -0800, John W. Krahn wrote: Mr. Shawn H. Corey wrote: On Sun, 2008-11-23 at 05:34 -0800, John W. Krahn wrote: You shouldn't do something with $line if $bytes_read is undefined: while ( my $bytes_read = read PATTERN, $line, 1920

Re: global and local confusion

2008-11-23 Thread John W. Krahn
Harry Putnam wrote: The program I'll post below is really only a test of a subroutine I want to use in a larger program. Trying to get the subroutine ironed out in this test script below so there is a little extra bumping around to get it executed as sub routine, but It fails with these errors:

Re: global and local confusion

2008-11-23 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sun, 2008-11-23 at 16:55 -0600, Harry Putnam wrote: The program I'll post below is really only a test of a subroutine I want to use in a larger program. Trying to get the subroutine ironed out in this test script below so there is a little extra bumping around to

Re: Date format search in the file

2008-11-22 Thread John W. Krahn
Sureshkumar M (HCL Financial Services) wrote: Hi All, Hello, I want to find the string which are having the date inside the file. Please help me how do I match it,below is my program and it's not returning anything. #!/usr/bin/perl use warnings; use strict; open(DATA,i)||die Unable to

Re: Date format search in the file

2008-11-22 Thread John W. Krahn
Dermot wrote: 2008/11/22 Sureshkumar M (HCL Financial Services) [EMAIL PROTECTED]: #!/usr/bin/perl # Always use these, particularly when things aren't working as expected. use strict; use warnings; open(DATA,i)||die Unable to open the file; while(DATA) { if($_=~/(\d{2})([\W])\1\2\1]/)

Re: awk command in script?

2008-11-21 Thread John W. Krahn
Owen wrote: You need to run something like this. Adapt to your requirements #!/usr/bin/perl -w use strict; while (DATA) { my $line = $_; if ( $line =~ /QQQ/ ) { my @bits = split; print $bits[$#bits -1]\n;

Re: awk command in script?

2008-11-20 Thread John W. Krahn
marys wrote: Hello: Hello, Does anyone know how to use ‘awk’ in a script? perl and awk have a lot of similar features so its usually preferable to use perl in a perl program instead of awk. It must have a different syntax than the unix analog, as does the ‘grep’ command. For grep, the

Re: How to determine the file type of a file passed as an input to the perl program ?

2008-11-20 Thread John W. Krahn
Amit Saxena wrote: Hi all, Hello, How to determine the file type of a file passed as an input to the perl program ? I want to have the same output as it's shown by file command in UNIX. file uses a database called /etc/magic to determine the file type. Although on my system it is located

Re: regexp - end of line question

2008-11-20 Thread John W. Krahn
sftriman wrote: I have data such as: A|B|C|44 X|Y|Z|33,44 C|R|E|44,55,66 T|Q|I|88,33,44 I want to find all lines with 44 in the last field. I was trying: /[,\|]44[,\$]/ which logically is perfect - but the end of line \$ doesn't seem right. How do I write: comma or pipe followed by 44

Re: regex {1,}

2008-11-20 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi, Hello, I am trying to use a regular expression to search for some words in a file after a few particular words/characters. Once I find the words I am looking for, I want to print only those words. Here's what I'm talking about. while(INPUT) { if

Re: printing element from a 'split' file

2008-11-19 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi, Hello, I am trying to split a file (where there are one or more spaces) that I am getting through a file handle that is fed into an array and then printing each element of the array on a seperate line. Here's what I have: As you can probably figure out I only

Re: Regular expression problem

2008-11-18 Thread John W. Krahn
howa wrote: Hello, Hello, I have two strings: 1. abc 2. abc The line of string might end with or not, so I use the expression: (.*)[$] Why it didn't work out? $ perl -le' for ( abc, abc ) { print; print $1 if /(.*)[$]/; } ' abc Unmatched [ in regex; marked by -- HERE in

Re: Two questions about split and map in a cookbook recipe

2008-11-17 Thread John W. Krahn
Telemachus wrote: Good morning, Hello, I'm using a recipe from The Perl Cookbook (11.10 for anyone browsing at home) to produce a record structure from items in a text file. The text file itself has a simple structure: field:value field:value field:value field:value field:value

Re: Two questions about split and map in a cookbook recipe

2008-11-17 Thread John W. Krahn
Telemachus wrote: On Mon Nov 17 2008 @ 10:21, John W. Krahn wrote: Set paragraph mode. while () { Read a paragraph into $_. In your example a paragraph is: field:value field:value field:value my @fields = split /^([^:]+):\s*/m; Since there are multiple lines

Re: Array manipulation

2008-11-16 Thread John W. Krahn
hotkitty wrote: Hi, Hello, I have two arrays, as follows: Array1=( date 11/01/2008 newstuff1, date 10/27/2008 newstuff2, date 10/24/2008 newstuff3 ) Array2=( date 11/01/2008 oldstuff1, date 10/31/2008 oldstuff2, date 10/30/2008 oldstuff3, date 10/29/2008 oldstuff4, date 10/28/2008

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread John W. Krahn
Kelly Jones wrote: Consider: perl -le '$hash{foo-bar} = 1; print $hash{foo-bar}' [no result] Using warnings and/or strict may have helped: $ perl -Mwarnings -le 'my %hash = (foo-bar, 1); print $hash{foo-bar}' Unquoted string foo may clash with future reserved word at -e line 1. Argument bar

Re: Quoting hash keys changes things sometimes

2008-11-15 Thread John W. Krahn
Chas. Owens wrote: On Sat, Nov 15, 2008 at 13:52, Kelly Jones [EMAIL PROTECTED] wrote: Consider: perl -le '$hash{foo-bar} = 1; print $hash{foo-bar}' [no result] perl -le '$hash{foobar} = 1; print $hash{foobar}' 1 I sort of understand this: in the first script, Perl treats foo-bar as a

Re: Processing files in a directory

2008-11-11 Thread John W. Krahn
Susheel Koushik wrote: use the PERL system command. Its a wrapper for system call on your host OS. ex: system(rm *.tmp); Why, when you can just do: unlink *.tmp; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in

Re: Using perl in a Bash-script to extract IP-addresses?

2008-11-11 Thread John W. Krahn
Chas. Owens wrote: On Mon, Nov 10, 2008 at 21:40, Rob Dixon [EMAIL PROTECTED] wrote: John W. Krahn wrote: Why not just: ipaddy=`awk '{ print $1 }' ipin.txt` But that still doesn't get you a comma-separated list. Erm, a Perl list? Rob Hey, if you throw an @ in front of ipaddy you get

Re: to read a line 2 lines above a line having a grepped string...

2008-11-11 Thread John W. Krahn
dilip wrote: hi all, Hello, suppose i have a file having the following data.. SN = TOM FDN = SALLY OPERATIONAL STATE = ENABLED Now suppose i grep the string ENABLED, i get the third line.But from this very line i need to go 2 lines above and get the SN value also.Please suggest .

Re: Using perl in a Bash-script to extract IP-addresses?

2008-11-10 Thread John W. Krahn
Stewart Anderson wrote: JC Janos wrote: I have a file containing IP addresses ranges, their negations, and comments. E.g., 1.1.1.1 # comment A 2.2.2.2/29 # comment B !3.3.3.3 # comment C !4.4.4.4/28 # comment D I need to extract those IPs

Re: hash slice??

2008-11-10 Thread John W. Krahn
Travis Thornhill wrote: Is there such a thing? Yes there is. I'm trying to take a HoH and make a reference to a sub-part of the hash. This doesn't work: my %sub_hash = $main_hash{'sub_hash'}; I get the following error: Reference found where even-sized list expected at ./my_buggy_program

Re: Using perl in a Bash-script to extract IP-addresses?

2008-11-09 Thread John W. Krahn
JC Janos wrote: Hi, Hello, I have a file containing IP addresses ranges, their negations, and comments. E.g., 1.1.1.1 # comment A 2.2.2.2/29 # comment B !3.3.3.3 # comment C !4.4.4.4/28 # comment D I need to extract those IPs ranges, rearrange

Re: merge 2 or more files together without creating new file

2008-11-05 Thread John W. Krahn
slow_leaner wrote: On Nov 1, 6:57 am, [EMAIL PROTECTED] (John W. Krahn) wrote: slow_leaner wrote: Let me just add this to be clear. I am so beginner, almost 4 moths, and not getting anywhere with perl. I need some fire in my heart to keep me going. I just want someone to show me how to fish

Re: pushing value to $t-src

2008-11-05 Thread John W. Krahn
Brian wrote: Hello again Hello, could someone please help me? I will try. $ZZ on line 38 is a single letter output from $string (in this case f) I would like to get this value pushed to $ZZ on line 11 Then you have to assign a value to it *before* line 11. as it

Re: whats the perl command to run/execute a program or script

2008-11-05 Thread John W. Krahn
itshardtogetone wrote: Hi, Hello, Whats the perl command to run a script or program. my $standard_output = qxprogram; my $error_code = system qprogram; exec qprogram; open my $PIPE, '-|', qprogram; perldoc -f qx perldoc -f system perldoc -f exec perldoc -f open perldoc perlopentut

Re: substitute multiple spaces with just one

2008-11-04 Thread John W. Krahn
Sharan Basappa wrote: Hi, Hello, I have string that has one or more spaces. I would like to replace them with a single space. $ perl -le' my $temp = 0 1 2 34; print $temp; $temp =~ tr/ //s; print $temp; ' 0 1 2 34 0 1 2 3 4 The simple code below replaces the spaces fine,

Re: substitute multiple spaces with just one

2008-11-04 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Tue, 2008-11-04 at 16:30 +0100, Rob Coops wrote: What you want to be doing is this: $temp =~ s/\s+/ /g; Actually to substitute multiple spaces with just one: $temp =~ s/ +/ /g; Or as some prefer: $temp =~ s{ [ ]+ }{ }gx; Not if speed is an issue: $ perl -le'

Re: perl reg. exp. (search and replace)

2008-11-03 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi all, Hello, I have a string which contains spaces. I need to replace those spaces with underscore, so I have written command like this $string=fsdfsdfsdf fsdfsdfsdf; chomp($string1 = ($string =~ s/\s+$/_/g)); \s+$ matches one or more of any whitespace

Re: Odd problems with alarm()

2008-11-03 Thread John W. Krahn
Matthew Tice wrote: I've setup a simple (well, I copied it from someone else and modified it) to monitor stale NFS mounts. Some preliminary testing seemed to go okay but this problem crept up on me this weekend. The script is as follows: #!/usr/bin/perl use warnings; use strict; if (@ARGV

Re: debugger exiting

2008-11-03 Thread John W. Krahn
Sharan Basappa wrote: Hi, Hello, I am using debugging for a program of mine. The debugger exits probably after a regex match fail. I am not sure why it should exit. Any ideas, clues? Regards main::(StTrAuto.pl:106): my @new_auto_tr = (); DB2 s main::(StTrAuto.pl:107):

Re: How to put a global variable in a package, accessible to usersof that package?

2008-11-01 Thread John W. Krahn
Dr.Ruud wrote: Mr. Shawn H. Corey schreef: 2) Perl does not have true constants. When you `use constant` you actually create a sub that returns a value. This: use constant VAR = someval; is the same as: sub VAR { return someval; } Perl has true constants. use constant isn't the same

Re: merge 2 or more files together without creating new file

2008-11-01 Thread John W. Krahn
slow_leaner wrote: On Oct 31, 10:27 am, [EMAIL PROTECTED] (Slow_leaner) wrote: Is there a way I can marge FILE2 into FILE1 or reverse together without creating a new merge file. I am not sure there are a better way to do it. If you give me some hint or help, i would appreciate it. thx. Here is

Re: Why doesn't this work: perl -e @s=([1,2],[3,4]); print $s[0][0];

2008-10-31 Thread John W. Krahn
Zembower, Kevin wrote: (This should probably be an easy one for someone.} Why doesn't this work: [EMAIL PROTECTED]:/usr/local/src/rrd$ perl -e @s=([a,b],[c,d]);print $s[0][0]; syntax error at -e line 1, near ][ Execution of -e aborted due to compilation errors. The shell interpolates your

Re: Why is my regex so slow?

2008-10-31 Thread John W. Krahn
Mark Wagner wrote: I've got a script I'm using to search through a list of Wikipedia article titles to find ones that match certain patterns. As-written, if you run it and supply '.*target.*' on standard input, it will process my test file in 125 seconds. '.*target.*' is inefficient because

Re: LWP::Simple

2008-10-28 Thread John W. Krahn
[EMAIL PROTECTED] wrote: ok I'm pretty much a noob here, so you have to expect some level of stupidity... ;-) I got this script off a site and have spent several hours trying to fix it yet I clearly still do not understand what exactly it is doing. To me it appears to have problems when there

Re: matching elements from array and print the results line by line from log file

2008-10-28 Thread John W. Krahn
slow_leaner wrote: Hi, Hello, I have a list of element in array that I would like to match the pattern in logs file. I have hard time take element from array and matching it. More then weeks now and don't know where to find in man page. perldoc -q How do I efficiently match many regular

Re: Curly braces and the logic of PERL

2008-10-27 Thread John W. Krahn
Brian wrote: Hello Hello, Years ago I used to work with FORTRAN, RPG GAP 2 and a smidgeon of basic. Code was written one line at a time, the first section of code was Input data, the next section was calculations, the last section was output. (For example, in the sample of code below, the

Re: Curly braces and the logic of PERL

2008-10-27 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Mon, 2008-10-27 at 17:05 +, Brian wrote: Why is it that some code has no curly braces after print; whilst in others I sometimes see one or more curly braces after it? Will there be a time when print; will fail because there isn't a curly brace following it,

Re: Curly braces and the logic of PERL

2008-10-27 Thread John W. Krahn
Brian wrote: Mr. Shawn H. Corey wrote: This code is written this way because the coder has been playing too much Perl Golf ;) The objective of Perl Golf is to write a program to do a simple task in the least number of characters possible. This, of course, makes it harder to read. I must

Re: match and putting in a variable with a single statement

2008-10-27 Thread John W. Krahn
Jenda Krynicky wrote: From: Chas. Owens [EMAIL PROTECTED] On Oct 24, 2008, at 11:00, Sharan Basappa [EMAIL PROTECTED] wrote: I was just trying to match a string and save it in a single statement as follows: $extracted = cp xyz; $state_var = $extracted =~ m/cp\s+(.*)/; print $state_var $1

Re: Reading a list of numbers from a file into a array

2008-10-26 Thread John W. Krahn
vendion wrote: Hello I am having trouble finding the correct syntax for reading a list of numbers from a file, it is open and can read from it, I tried with while (INPUT) { chomp; @some_array = $_; print @some_array\n; } my @some_array; while ( INPUT ) { chomp;

Re: recurse dir files

2008-10-26 Thread John W. Krahn
Brian wrote: Hello Hello, I would like to do a recursive search of directories and files, checking to see if a file contains a certain string. STDIN will be a string containing whitespace(s). As soon as I hit enter, I would like dummy.txt to be time stamped and again at termination. I'm

Re: recurse dir files

2008-10-26 Thread John W. Krahn
Brian wrote: John W. Krahn wrote: Brian wrote: I would like to do a recursive search of directories and files, checking to see if a file contains a certain string. STDIN will be a string containing whitespace(s). As soon as I hit enter, I would like dummy.txt to be time stamped and again

Re: recurse dir files

2008-10-26 Thread John W. Krahn
Brian wrote: John W. Krahn wrote: Brian wrote: Unknown PerlIO layer mmap at mysearch.pl line 14, STDIN line 1. I thought that Windows supported memory mapping, oh well. Cannot open file dummy.txt No such file or directory at mysearch.pl line 14 STDIN line 1. the script is placed under

Re: How to Determine why a File Failed to Open

2008-10-26 Thread John W. Krahn
AndrewMcHorney wrote: Hello Hello, Is there a way in Perl to find out why a file failed to open? I am working on a script that is opening and reading a lot of files. This script is right now being written on a Windows based system. perldoc perlvar [ *snip* ] $OS_ERROR $ERRNO

Re: Output

2008-10-24 Thread John W. Krahn
Brian wrote: Hello Hello, Having played around for a while, I am able to get a reasonable result using Example 1, the unreasonable part being that l gets added to the end of the file, I can only presume here that it is duplicating the last 2 characters of the last line in the file, that

Re: ignore directories with File::Find?

2008-10-24 Thread John W. Krahn
protoplasm wrote: On Oct 23, 2:09 am, [EMAIL PROTECTED] (John W. Krahn) wrote: Perhaps you need to use the -xdev switch for find to ignore other file systems? Thank you, John. That certainly helped. It now ignores the mounted file systems but still traverses hidden directories. I must

Re: Use of dollar signs before subroutine definition

2008-10-24 Thread John W. Krahn
Kelly Jones wrote: I saw something like this in a mimedefang tutorial: sub foo () {return 1;} By trial and error, I discovered this means: foo takes EXACTLY four arguments, no less, no more. Where can I learn more about this syntax/feature?

Re: ignore directories with File::Find?

2008-10-23 Thread John W. Krahn
protoplasm wrote: I ran find2perl to give me some output that I included below (in Sub_directory). If I have no network shares mounted it runs fine. But I have some shares mounted (sftp, or smb, etc.) via Nautilus, the below script really takes a long time. It begins to search through ~/.gvfs

Re: trouble with a regular expresion

2008-10-23 Thread John W. Krahn
Kirk Wythers wrote: Below is snipit of code that is intended to read in the station_id from the header of each example file. In each case the reg expression is supposed to find the 6 digit number within the parentheses. Both files contain 6 lines in the header. For some reason the reg

Re: trouble with a regular expresion

2008-10-23 Thread John W. Krahn
Kirk Wythers wrote: On Oct 23, 2008, at 11:09 PM, John W. Krahn wrote: Kirk Wythers wrote: Below is snipit of code that is intended to read in the station_id from the header of each example file. In each case the reg expression is supposed to find the 6 digit number within the parentheses

Re: Reading from multiple sockets.

2008-10-22 Thread John W. Krahn
Kammen van, Marco, Springer SBM NL wrote: From: Peter Scott [mailto:[EMAIL PROTECTED] Subject: Re: Reading from multiple sockets. On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM NL wrote: I'm pretty new to working with sockets in perl, looked around for days for a proper

Re: Using a variable in a =~ match??

2008-10-22 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi John, I picked up the Perl book last week so all of your whys will get one answer. Because that the way I thought it would work! There are a *lot* of Perl books out there. Which one in particular did you pick up? perldoc -q How do I find yesterday.s date :

Re: Conditional replace

2008-10-22 Thread John W. Krahn
Brian wrote: Hi Hello, ARGV0 will = AB7Z001 ARGV1 will = AB7Z002 ARGV2 will = 01/01/1900 I would like to read a file, locate AB7Z001 (but not AB7Z0011, so a space at position 8 in string ) Upon location of value in argv0 replace it with argv1. Then, at the first instance of a date replace

<    4   5   6   7   8   9   10   11   12   13   >