Re: Merging lines in a file

2004-08-29 Thread John W. Krahn
Jan Eden wrote: Hi, Hello, I had the following task: Open a file, read it and merge all pairs of lines containing a certain number of tabs. Example: Blablabla abc cab bca 123 453 756 Blablabla Blablabla Here, lines 2 and three should be merged, while the other lines should remain untouched. Expec

Re: Merging lines in a file

2004-08-29 Thread John W. Krahn
Jan Eden wrote: Hi, Hello again, I had the following task: Open a file, read it and merge all pairs of lines containing a certain number of tabs. Example: Blablabla abc cab bca 123 453 756 Blablabla Blablabla Here, lines 2 and three should be merged, while the other lines should remain untouched.

Re: shift question

2004-08-30 Thread John W. Krahn
[EMAIL PROTECTED] wrote: I found this in a template for creating subroutines, this is the base that is created when you use the template to create the subroutine. So now the newbie part, why would you place "my $par1 = shift;" in the subroutine template, and what does it do?? Basically I am trying

Re: Could this be made shorter and cleaner?

2004-08-30 Thread John W. Krahn
Gavin Henry wrote: Hi all, Hello, This is my first real go at a perl script. Thoughts? Subject: Could this be made shorter and cleaner? Yes. # Globals

Re: Could this be made shorter and cleaner?

2004-08-31 Thread John W. Krahn
Gavin Henry wrote: It looks like 99% of the code in both blocks is exactly the same. You should factor out duplicated code. my $msg = $backup ? 'failed' : 'completed'; my %mails = ( To => $to, From=> $from, Subject => "Remote backup $msg from $ENV{HOSTNAME} on $time", Mess

Re: A simple way? A Perl way?

2004-08-31 Thread John W. Krahn
Jerry Preston wrote: Hi! Hello, I am looking for a simple Perl way to decode the following, which can be any grouping of number 2-8,9,11,18-21 Into 2,3,4,5,6,7,8,9,11,18,19,20,21 $ perl -le' print join ",", map /(\d+)-(\d+)/ ? $1 .. $2 : $_, split /,/, "2-8,9,11,18-21"' 2,3,4,5,6,7,8,9,11,

Re: A simple way? A Perl way?

2004-09-01 Thread John W. Krahn
Tim Johnson wrote: Just for the sake of showing another way to do it... my $input = "2-8,9,11,18-21"; $input =~ s/-/\.\./g; print join(',',eval($input)); or if you don't want to print out the list but iterate through it... #

Re: Splicing Hash problem - possible with "map"?

2004-09-06 Thread John W. Krahn
Gunnar Hjalmarsson wrote: Edward WIJAYA wrote: Just thought whether it is possible to do it with "map" function? Make it into one-liner? It is. my %myNEWhash = map { $_, delete $myhash{$_} } grep /^1\D/, keys %myhash; Very good Gunnar! But the regexp may not work in all cases. my %myNEW

Re: Reading Multiple Lines

2004-09-08 Thread John W. Krahn
Eduardo Vázquez Rodríguez wrote: Hello Hello, I am writing scripts that process big files which contains too many lines (aproximately 700 000 lines per file). My strategy until now to solve this problem is reading line per line, something like this while () { dosomethingwith($_); } Is there

Re: Copying files from One PC to another.

2004-09-10 Thread John W. Krahn
Denham Eva wrote: Hello Listers. Hello, Please I am a beginner. I am making tentative steps to creating a script which will keep my Notebook and Workstation at work in sync. My first attempt is just to copy the files from the one to local. Here is my script - it works, but I suspect there should be

Re: Copying files from One PC to another.

2004-09-10 Thread John W. Krahn
[ Please do not top-post. TIA ] [EMAIL PROTECTED] wrote: From: Denham Eva <[EMAIL PROTECTED]> Please I am a beginner. I am making tentative steps to creating a script which will keep my Notebook and Workstation at work in sync. My first attempt is just to copy the files from the one to local. Here

Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread John W. Krahn
Edward WIJAYA wrote: Hi, Hello, I have a simple code that take currently fixed to take 3 input files and append each line of these files together. I wish to know is there anyway I can write the code more flexibly so it can dynamically take the input argument - from minimum 2 files to more. Is there

Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread John W. Krahn
Errin Larsen wrote: On Fri, 10 Sep 2004 12:44:51 -0400, David Greenberg <[EMAIL PROTECTED]> wrote: foreach( @ARGV ) { open IN, $_ or die "Couldn't open $_: $!\n"; chomp( my @data = ); close IN; foreach( @data ) { s/\s+//g; } foreach( 0..$#data ) { $results[$_] .= $data[$_]

Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread John W. Krahn
Bee wrote: I would suggest to write in this way : my @res = (); foreach( @ARGV ) { open IN, $_ or die "Couldn't open $_: $!\n"; my @data = ; close IN; s/\s+//g for @data; @res = ( @res, @data ); You are copying the @res array. It would be more efficient using

Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread John W. Krahn
Errin Larsen wrote: Ok ... please forgive my n00b-ness, but can you help me understand a couple of things here. This part: shift (@results) . $line Is it the same as: shift @results . $line I'm thinking "no". But I don't know what the difference is. I also don't understand what exactly tha

Re: How to dynamically taking the multiple input arguments?

2004-09-11 Thread John W. Krahn
Edward WIJAYA wrote: Hi John, Hello, I tried your code. But I still cannot remove the whitespace from each line. Suppose I have two files. fileA.txt:fileB.txt: A B A B What I get is: A B A B instead of AB AB I tried to play around with this section of your code but of no

Re: Conceptual questions about 'pack'

2004-09-12 Thread John W. Krahn
Bee wrote: Hi, I am very newbie for using the function 'pack', and here I have some questions : Have you read the documentation for pack? perldoc -f pack And unpack? perldoc -f unpack Have you read the pack and unpack tutorial? perldoc perlpacktut Q1. Can I expect that pack can do this for me ?

Re: Regex help

2004-09-13 Thread John W. Krahn
Johnstone, Colin wrote: Hi Jim, Hello, (my name is John BTW) rather than re-invent the wheel I would prefer if you could fix this regex I believe it covers all invalid characters one would encounter s/[\w\&%'[EMAIL PROTECTED](\)&_\\+,\.=\[\]]//g; Most of those characters are valid in DOS file name

Re: String to Numeric of an Array

2004-09-14 Thread John W. Krahn
Edward WIJAYA wrote: Hi, Hello, How can I change the value of this array: @array = ['1','2','3']; #which contain "string" numeric to @arrayNum = [1,2,3]; #as pure numeric As far as perl is concerned they are the same. If you use a string in numeric context it becomes a number and if you use a nu

Re: split function

2004-09-14 Thread John W. Krahn
c r wrote: Hi! Hello, Can the perl split function split a random 40 character string into five 8 character strings? No. With random I mean that there is no special pattern in the 40 character string that can be used as split markers. You should probably use a match operator. my @strings = $string =

Re: declaring with my

2004-09-14 Thread John W. Krahn
Errin Larsen wrote: Hi all, straight out of the Learning Perl book (3rd edition, page 275) is this code: my @numbers; push @numbers, split while <>; foreach (sort { $a <=> $b } @numbers) { printf "%20g\n", $_; } This works flawlessly. My question is why can't I put that variable declaration in

Re: declaring with my

2004-09-14 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Errin Larsen wrote: my @numbers; push @numbers, split while <>; why can't I put that variable declaration in the push function? like this: push my @numbers, split while <>; The original code could be written as: my @numbers; while

Re: building substrings

2004-09-15 Thread John W. Krahn
David Gilden wrote: Hello, Hello, I am building a primary key for a database, and I guess the first question would be how safe is a key made from the last 4 digits of a social security num and the first 3 letters of the last name. Do you mean safe as in unique? Or do you mean safe because you ar

Re: Time Skip

2004-09-16 Thread John W. Krahn
Anish Kumar K. wrote: $filename = "data_logfile" .(localtime). ".txt"; open(LOG, ">>$filename") || die "cannot append: $!"; when I compile the file is says "Invalid argument". This is because of the colon character. Suppose after one activity I want to update the log activities in one file say da

Re: $^ I

2004-09-16 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Here is my entire code. I need help in getting the in place editor working b/c from my reading this is correct! ## Set pragmas use strict; use diagnostics; use MIME::Lite; use Net::FTP; Only all lowercase modules are pragmas, the rest are

Re: command line option with -ne to print newline

2004-09-17 Thread John W. Krahn
Ramprasad A Padmanabhan wrote: Quick question, I want to run perl -ane '/REMARKS/ && print $F[1]' FILE1 FILE2 the problem is that there is no newline at the end of the every print. so I have to do perl -ane '/REMARKS/ && print $F[1] . "\n"' FILE1 FILE2 I thought there is a switch in

Re: how to get and convert time

2004-09-17 Thread John W. Krahn
Franklin wrote: Hello: Hello, My operating system is freebsd and its time is GMT time which I can't change. How can I write a perl script to get the exact time(Hour,minute,second) and change it to US ET? All Unix systems (AFAIK) run on UTC (GMT for you old timers, Zulu Time for you military types)

Re: cp command error check

2004-09-17 Thread John W. Krahn
Urs Wagner wrote: Hello Hello, This does not work. `cp $srcfile $dstfile`; || do { print "cannot copy $srcfile to $dstfile"; }; do is also execute if cp working fine. Whz is this so? The next thing I would like to know how I can print the cp's error message. use File::Copy; copy( $srcf

Re: truncate word

2004-09-20 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi Hello, I have a file which contains a number of instances of the word "FINAL". I need to truncate all the instances of this word and create an output string of the rest of the words in the same line in the file. Rest all lines not containing the word are to be ignored. F

Re: truncate word

2004-09-20 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: [EMAIL PROTECTED] wrote: I have a file which contains a number of instances of the word "FINAL". I need to truncate all the instances of this word and create an output string of the rest of the words in the same line in the file. Rest all

Re: NOT in a regex?

2004-09-20 Thread John W. Krahn
Colm Gallagher wrote: Hi Folks, I'm trying to pull a use case description out of a text file (actually an MS Word doc, but I've already used Win32:OLE to pull the text). The converted text comes out something along the lines of Version Change Date Changed By Change Description 1 Date A.N. Other

Re: Delete all hash entries except for a specific list

2004-09-21 Thread John W. Krahn
Bob Showalter wrote: Consider, my %hash = ( foo => 1, bar => 2, baz => 3, qux => 4, ); I would like to remove all the entries in the hash except for 'bar' and 'qux'. (Actual hash has other entries which can vary at runtime. I know that I only want to keep 'bar' and 'qu

Re: array rotate question

2004-09-21 Thread John W. Krahn
Ing. Branislav Gerzo wrote: Hello! Hello, I am thinking about making clear and short script to rotate array, let's say: input: @list = (1 .. 20); $start = 10; #starting position $values = 10;#how much values in result how to get output: @result = ( 5, 6, 7, 8, 9, 11, 12, 13, 14, 15

Re: Run a process in the background

2004-09-22 Thread John W. Krahn
Errin Larsen wrote: Hi Perlers, Hello, I know that questions like this get asked all the time, but I guess it's just my turn to ask 'em! I need to kick of some processes in my script. However, the script needs to kick them all off at once and then stick around to do some other things. I'm kinda n

Re: How to check the FILE HANDLE STATUS ???

2004-09-24 Thread John W. Krahn
Madhu Reddy wrote: hi, Hello, I want to check the status of File handle before reading/writing to file ? How to do this ? like following open(FH_IN_FILE, ">file.txt"); # This statement is executed by some other function close(FH_IN_FILE); print FH_IN_FILE "SOME DATA"; here before writing to f

Re: How do I get rid of ""

2004-09-24 Thread John W. Krahn
William Martell wrote: Hi All, Hello, This "" is in a text file that I am working with. I am trying to remove it, but it seems to be a different character in different places throughout the text, even though to me, when viewed in Textpad text editor, it looks the same. Is there a special he

Re: Daemon that starts other Daemons

2004-09-24 Thread John W. Krahn
Bob Showalter wrote: Errin Larsen wrote: Ok ... so with some research and playi^H^H^H^H^Htesting I've found the answer to what's really been bothering me. If you *really* want to understand the nuts and bolts of all this, Stevens' _Advanced Programming in the UNIX Environment_ is a must. http://www

Re: Need help in File::Stat

2004-10-12 Thread John W. Krahn
Chandrakant Reddy wrote: Hi Hello, I wrote this simple script : #!/usr/local/bin/perl use strict ; use warnings ; use File::Stat ; Is there a reason that you can't use the built-in stat function or the core module File::stat? my $filename = "/tmp/cvr.txt" ; my $stat = new File::Stat($filename) o

Re: Map out a directory heirarchy

2004-10-12 Thread John W. Krahn
Harry Putnam wrote: Harry wrote: This new coding although easier to look at and probably more efficient, isn't really any faster or at least not appreciably. It still goes to each and every numbered file. John replied: In most file systems the file names are not stored in any particular order so i

Re: Perl equivalent to the unix 'cut' command

2004-10-14 Thread John W. Krahn
Dave Kettmann wrote: Howdy list, Hello, Subject speaks for itself.. Need to find a function or module to work like the 'cut' command. I have a file with multiple fields and i need to 'cut' out 2 of the fields. Looked thru CPAN for cut, but didnt find anything, Really? I found it right away. http:/

Re: how to assign an external command aoutput to an array

2004-10-15 Thread John W. Krahn
Mauro wrote: I have to assign output of ssh [EMAIL PROTECTED] sar -u 1 1|awk '/%usr%sys%wio %idle/ { getline ; printf "%i %i %i %i", $2, $3, $4, $5 }' to an array. The output looks like: 0 0 0 100 if I did: my @pippo=qx'ssh [EMAIL PROTECTED] sar -u 1 1|awk \'/%usr%sys%wio %idle/ {

Re: Reference syntax...

2004-10-15 Thread John W. Krahn
Wiggins d Anconia wrote: Usually when you need this is when you have multiple depths of references and the syntax becomes ambiguous to the interpreter. Something like, @{$hashref->{$scalar}} In this case without the {} the interpreter can't tell if you mean, Yes, the interpreter can tell because of

Re: Piping output to and from external perl routine

2004-10-15 Thread John W. Krahn
Dan Fish wrote: Is there an easy way to pipe output to an external perl routine and then pipe the output of that routine back in for more processing? In particular I want to use LWP::UserAgent to grab a web page, pipe the output to Tom Christiansen's "striphtml" routine (http://www.cpan.org/authors

Re: Piping output to and from external perl routine

2004-10-16 Thread John W. Krahn
Dan Fish wrote: Yes... I could do that, and HAVE actually done that before for other routines due to the "fire-fighting" time constraints of the moment :-) This time I was hoping to increase my *very-limited* knowledge of Perl for a more elegant solution, because I'm sure I'll need to do something

Re: Why are file handles wierd?

2004-10-16 Thread John W. Krahn
Siegfried Heintze wrote: I asked this question previously, but received no response. I sure the reason was that I was far too verbose. So let me make it simple: What is the logic that says all data types will be prefixed with special character such as "$" or "%" or "@" except file handles? Why are

Re: Opening file($ARGV) with Getopt - failing

2004-09-28 Thread John W. Krahn
Edward Wijaya wrote: > Hi, Hello, > Why my code below fail to open and > print the file contents > > when I do: > > perl mycode.pl -f filename > > > __BEGIN__ > use strict; > use warnings; > > use Getopt::Std; > use vars qw($f); > getopts('f:'); getopts( 'f:' ) creates the variable $opt_f and store

Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-28 Thread John W. Krahn
Gavin Henry wrote: I really like Perl, but lately everywhere I seem to go and talk to say I shouldn't be learning Perl as it's old and Python is better. Fortran, Cobol, Lisp, C and Basic are older and people still use them. There are always people who will say that X is better then Y (and people wh

Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-28 Thread John W. Krahn
Gavin Henry wrote: By the way, my program now works great thanks to your sub advice. I still have some cleaning to do, like my resize sub abd incorporating file tests etc. You can see how bad my program is at: http://www.perl.me.uk It's called ebaypics Advice from you in a new thread, would be very

Re: How to find if a key exist in hash?

2004-09-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: %a = ( "a" => 1, "b" => 2, "c" => 3 ); $searchKey = "a"; print "Found $searchKey" if defined($a{$searchKey}); Try that with this hash: my %a = ( a => undef, b => undef, c => undef, ); defined() does not tell you if a key exists. perldoc -f exists Jo

Re: how to open a file with 666 permission

2004-09-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hai! Hello, My requirement is to open file with 666 permissions.[If fine doesn't exists it should get created ].Iam doing as below,is this ok. === sysopen(LOG,"$main::TRACELOGFILE",O_CREATE,0666) or die "Can't open trace file $main::TRACELOGFILE"; ==

Re: how to open a file with 666 permission

2004-09-29 Thread John W. Krahn
Bob Showalter wrote: [EMAIL PROTECTED] wrote: My requirement is to open file with 666 permissions. You need to set umask to 0 before creating the file. But don't do that. It's inadvisable to mess with the umask in a program, IMO. If the user wants to create files as 666, let him set the umask befor

Re: how to open a file with 666 permission

2004-09-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hey guys ! Thanks for the support .the following is the code I have written. Working fine. === open(LOG,">$main::TRACELOGFILE") or die "Can't open trace file $main::TRACELOGFILE"; system("chown XXX:Y $main::TRACELOGFILE"); system("chmo

Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-29 Thread John W. Krahn
Gavin Henry wrote: Randal L. Schwartz said: Remember "new coke", and how long we had that. (If you're old enough to remember that fiasco.) Again, thanks for this. My morale is now completely topped up, so I am going to shell out for Programming Perl, although I do have the CD Bookshelf 3.0 (better

Re: current directory

2004-09-29 Thread John W. Krahn
Urs Wagner wrote: Hello Hello, How can I find out the current directory? I call chdir, afterwards I should switch back to the old one. perldoc Cwd John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Need help with script

2004-09-29 Thread John W. Krahn
Ramprasad A Padmanabhan wrote: On Wed, 2004-09-29 at 18:55, PerlDiscuss - Perl Newsgroups and mailing lists wrote: I have a file with the following format Object1 "Description1" Object2 "Description" Object3 "Description" I would like the output in the following format object1<...tab>Descriptio

Re: OR in a regex

2004-09-30 Thread John W. Krahn
Colm Gallagher wrote: Oops, that example I gave actually works It's always better to give the whole problem... (? What it's actually doing is matching the alternates but looking at the string in reverse order. I want to have look at the string in forward order for the alternates, but still keep th

Re: Need help with script

2004-09-30 Thread John W. Krahn
Errin Larsen wrote: Hi Perlers, On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro <[EMAIL PROTECTED]> wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: I would like the output in the following format object1<...tab>Description1 object2<...tab>Description2 object3<...tab>Descr

Re: Need help with script

2004-09-30 Thread John W. Krahn
Paul Johnson wrote: On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote: perl -l -00pe's/\n/\t/;s/\"//g;' FILENAME $ perl -MO=Deparse -l00pe's/\n/\t/;s/\"//g' BEGIN { $/ = "\n"; $\ = "\000"; } In your example you have removed the -0 switch so it is doing something completely different. John -- u

Re: printing block of text

2004-09-30 Thread John W. Krahn
Murphy, Ged (Bolton) wrote: I'm trying to print a block of code using 'print < #!/usr/bin/perl print < Can't find string terminator "TEST" anywhere before EOF at photo.pl line 3. Anyone got any ideas as to why it's doing this? perl is looking for a string terminator that looks like "\nTEST\n". You

Re: difference between "@_" and "shift"

2004-09-30 Thread John W. Krahn
Chris Devers wrote: The former is a variable; the latter is a function. @_ is one of Perl's "pronoun" variables: just as $_ refers to "that" which you were most recently working with, @_ refers to "those" which you were most recently working with. $_ is a scalar -- "it" or "that"; a single thi

Re: Problem with subroutines with hash and var as input

2004-10-01 Thread John W. Krahn
Edward Wijaya wrote: Dear Sirs, I have the following code, that take Hash of Hash as an iput. Then I have function (see below) that takes a hash and a variable as input. This function will count the elements of secondary hashes and delete the hash, if it is below certain variable limit. So with thi

Re: Problem with subroutines with hash and var as input

2004-10-01 Thread John W. Krahn
Edward Wijaya wrote: On Fri, 01 Oct 2004 07:41:43 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote: Either put the scalar first in the list or pass a reference to the original hash. Now, I also tried with pass by reference my ($HoH,$limit) = @_; foreach my $k ( keys

Re: Problem with subroutines with hash and var as input

2004-10-02 Thread John W. Krahn
Edward Wijaya wrote: On Fri, 01 Oct 2004 08:58:44 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote: Since $HoH now contains a reference to a hash you have to dereference it properly. delete $HoH->{ $k } if keys %${ $HoH->{ $k } } < $limit; return %$HoH; I apologize for

Re: Reg Exp

2004-10-05 Thread John W. Krahn
Mallik wrote: Dear Friends, Hello, I have the below code. my $a = ":-:m:-:a:-:l:-:i:-:k"; # Here each letter is separated by :-: my $del = ':-:'; # Delimeter my $b; while ($a ne $b) { $a =~ /^$b$del(.?)($del)?/; my $c = $1; print "$c\n"; $b .= $del . $c; } The above code is working

Re: References to anon array

2004-10-05 Thread John W. Krahn
Adam wrote: I am expecting in both examples the same result: Example1: the same references Example2: the same references However, I get: Example1: different references Example2: the same references What am I missing? #Example1 my $r1 = [1, 3]; Store a reference to an anonymous array in a scalar. my

Re: Reg Exp

2004-10-05 Thread John W. Krahn
[Please do not top-post. TIA] David le Blanc wrote: On Tue, 05 Oct 2004 04:03:21 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote: Mallik wrote: I have the below code. my $a = ":-:m:-:a:-:l:-:i:-:k"; # Here each letter is separated by :-: my $del = ':-:'; # Delimeter my $b

Re: Passing shell variables to PERL

2004-10-05 Thread John W. Krahn
Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON["varname"], is there something compatible in perl. You can do the same in perl with the special hash named %ENV. for instance: print $ENV{'

Re: sum a column

2004-10-06 Thread John W. Krahn
rmck wrote: Hello, Hello, Im trying to sum up a column from my results. Help. current output: Date_Time, SRCIP, DSTIP, TOTALBYTES 01-01-2004 12:56:48, 192.168.1.1, 192.168.2.2, 2768 Sum Of Bytes = 2768 01-01-2004 12:56:48, 192.168.2.2, 192.168.1.1, 438 Sum Of Bytes = 876 01-02-2004 16:49:45, 192.

Re: Passing shell variables to PERL

2004-10-06 Thread John W. Krahn
[Please do not top-post. TIA] Jeff Westman wrote: On Tue, 05 Oct 2004 15:30:59 -0700, John W. Krahn wrote: Jim wrote: Willy Perez wrote: Is there a method to pass a shell assigned variable to perl? For ex: ABC=xyc perl -ne 'print $ABC' In awk you could use ENVIRON["varname"]

Re: getting one hash out of multiple files

2004-10-06 Thread John W. Krahn
Folker Naumann wrote: Hi there! Hello, I'm fairly new to Perl and need some help to acomplish a (simple?) task. I extract strings from some logfiles, namely an ip-adress and bytes, by using regexes. I use a hash to store ip-adress and associated bytes. First i packed all logs in a temporary file

Re: getting one hash out of multiple files

2004-10-07 Thread John W. Krahn
Folker Naumann wrote: John W. Krahn wrote: This may work as it doesn't slurp the whole file(s) into memory: use warnings; use strict; use Socket; my %ipload; { local @ARGV = @sortlist; while ( <> ) { next unless / (\d+\.\d+\.\d+\.\d+) \w*\/\w* (\d+) [A-Z]+/ my $ip

Re: Re Finding file

2004-10-07 Thread John W. Krahn
Charlene Gentle wrote: Hi Hello, This is what I'm using to find the file. .I still can't delete the file perldoc -f unlink or replace it with the file I created. perldoc File::Copy se strict; use File::Find; use CGI qw(:standard); my $query = param("Toetsss"); undef $/; find( sub { return if

Re: pass a filehandle then use it in grep{}?

2004-10-09 Thread John W. Krahn
West, William M wrote: my @array =grep {-d "$directory\/$_"} readdir ; gives me this error:: Type of arg 1 to readdir must be HANDLE (not ) at ./subdirs.pl line 30, near ";" Execution of ./subdirs.pl aborted due to compilation errors. The expression "readdir ;" is the same as "readdir readline LS2;

Re: pass a filehandle then use it in grep{}?

2004-10-09 Thread John W. Krahn
West, William M wrote: oddly- the grep documentation in perldoc doesn't even mention filehandles. readdir does show proper use though- readdir does not use a filehandle and therefore does not show the proper use of them. The opendir/readdir/rewinddir/seekdir/telldir/closedir functions all use d

Re: A problem of pattern matching

2004-10-09 Thread John W. Krahn
Teng Wang wrote: I wanna match a specific pattern using grep(). My pattern has two parts: 1. exclude "." or ".." (to exclude the current and parent directory in unix) 2. the file type is jpg. The first pattern I am using is !/^\.\.?$/ The second is /\.jpg$/i How to combine them together? using t

Re: Map out a directory heirarchy

2004-10-09 Thread John W. Krahn
Harry Putnam wrote: I want to get a daily list of all the directories under a kind of large (by home standards) news heirarchy. I know a little about using File::Find but wonder if there is a better way. Here are the things one runs into with File::Find. if you run it looking for type d (-d) direct

Re: Why are file handles wierd?

2004-10-18 Thread John W. Krahn
Chris Devers wrote: On Sat, 16 Oct 2004, Brian Gunlogson wrote: A filehandle is kinda like a namespace for the file. It shouldn't have a datatype, because it doesn't contain data. Files don't contain data?? He said *filehandles* don't contain data, not files. :-) Which is not strictly true or the

Re: Reg ex : tabs/spaces

2004-10-18 Thread John W. Krahn
Ajey Kulkarni wrote: Thanks a ton Gunnar, How about the intermediate blanks? Is there a way to recursively take all blanks/tabs that occur?? word=Detail Design Activity Included# I would like to remove the blanks here.. Recursion is not required. $word =~ tr/ \t//d; John -- use Perl; program fulfil

Re: Why are file handles wierd?

2004-10-18 Thread John W. Krahn
Shaw, Matthew wrote: No one has mentioned (I think) that filehandles are actually 'typeglobs' Scalars, arrays, hashes, subroutines, filehandles and directory handles are all part of a typeglob. $ perl -le' $x = 987; @x = qw/a b c d/; sub x { print qq/z is "@z" "@_"/ } *z = *x; z( $z ) if $z == 98

Re: Generate a perl list file

2004-10-19 Thread John W. Krahn
[ Please do not top-post. TIA ] [ Please TRIM your posts. TIA ] [ Please don't reply to a previous post unless you are contributing to that thread. TIA ] Li, Aiguo (NIH/NCI) wrote: Dear all. Hello, I have a tab delimited file as follow: V namep 1.0 AAA 0.001 0.9 BBB

Re: Broken Subroutine

2004-10-20 Thread John W. Krahn
Gunnar Hjalmarsson wrote: Ron Smith wrote: my @basenames = &basenames(@paths); sub basenames { foreach (@_) { if ($_ =~ /(\w+)\.\d+\.\w+$/) { @basenames = $1; # print "@basenames\n"; That line assigns to @basenames the extracted basename from the last path only,

Re: Broken Subroutine

2004-10-20 Thread John W. Krahn
Ron Smith wrote: Here's the problem: My input looks like the following: C:\Perl\scripts\shots\sp2\shot_1\dir.txt C:\Perl\scripts\shots\sp2\shot_1\drames.txt C:\Perl\scripts\shots\sp2\shot_1\filename.0001.cin [snip] C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0008.rgb C:\Perl\scripts\sho

Re: How to remove trailing zero

2004-10-25 Thread John W. Krahn
Khairul Azmi wrote: Can somebody help me how to remove the trailing zero from an ip address $ip_add = "010.200.020.000"; The output should be "10.200.20.0"; I''ve been trying many regex techniques but still unsuccessful. $ perl -le'$_ = "010.200.020.000"; print; s/\b0+(?=\d)//g; print' 010.200.020

Re: Populating HASH from file

2004-10-25 Thread John W. Krahn
Jeff Borders wrote: I need to dump a plain text file that has the format of: key = value (ie. question answer) into a hash. I'm writing a simple learning tool to help me learn some basic korean terminology. Would someone be kind enough to point me in the right direction. -Jeff Borders korean.txt:

Re: problem printf

2004-10-25 Thread John W. Krahn
deny wrote: That isn't only perl code, it's incomplete, and it doesn't use 'printf'. Show us more code and explain your problem fully. thanks for your help here is the complete code #!/usr/bin/perl use warnings; use strict; use MD5; use Digest::MD5; require 'find.pl'; use File::Find; $md5 =

Re: Populating HASH from file

2004-10-25 Thread John W. Krahn
Edward WIJAYA wrote: Mine is not as elegant as J.Krahn's or Jeff's. But it's an alternative. I am just glad to contribute at least something to the forum I have owed so much... --- use strict; use warnings; use Data::Dumper; my %hash = (); while () { s/\s//g; You may be

Re: using 'my' problem

2004-10-27 Thread John W. Krahn
Murphy, Ged (Bolton) wrote: In order to use the array @files in the below code outside of the subroutine, so I need to declare @files globally? You could but it is not really necessary. I'm getting errors at the moment: Global symbol "@files" requires explicit package name That is because you have

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Assign each line to the $_ variable and try this to get the number of instances of < and > The match operator works on $_ by default. If you match on < or > globally and assign it to an array like so: @rights = m/\/g; See the FAQ for a more efficient way to do this. perldoc

Re: Recursively counting a matching pattern on a single line.

2004-10-27 Thread John W. Krahn
S.A. Birl wrote: On Oct 27, [EMAIL PROTECTED] ([EMAIL PROTECTED]: Brian: The regular expression: Brian: Brian: m/^<(><)*>$/ Brian: Brian: will ensure that it starts with < and ends with > and anything in between Brian: will be "><" which I think should do the trick. That logic is pretty hairy B

Re: Comparing two directories

2004-10-28 Thread John W. Krahn
Vladimir Lemberg wrote: Hi, Hello, Could you help me to find what's wrong in my script? I need to compare two directories and if file exists in both - print it. die "Usage: 2 arguments must be passed i.e. file1 file2\n" if @ARGV != 2; opendir DIR1, $ARGV[0] or die "couldn't open $ARGV[0] for readin

Re: Accessing 2D array

2004-10-28 Thread John W. Krahn
Khairul Azmi wrote: I've been trying to solve this problem using many techniques I found on the websites but still unsuccessfully sub func { my (@local_array) = @_; for (my $i=0;$i<@local_array;$i++) { for (my $j=0;$j<@local_array[$i];$j++) { print "$local_array[$i[[$j] ";

Re: Assigning regexpression to a variable

2004-10-28 Thread John W. Krahn
Prabahar Mosas wrote: Hai, Hello, I have problem to assign a regular expression into a variable. If any one know regarding this mail me as early as possible. If it is cannot give me alternative solution. specimen coding ** $value = 2422; $reg = '/\d/'; The slashes (/) are the de

Re: Accessing 2D array

2004-10-28 Thread John W. Krahn
Khairul Azmi wrote: Thanks for the solution. Not sure if this is still on topic but I then add an additional parameter to the subroutine sib func { my (@local_array, $local_value) = @_; print "$local_value \n"; for my $array ( @local_array ) { for my $element ( @$array ) { pri

Re: Assigning regexpression to a variable

2004-10-29 Thread John W. Krahn
Prabahar Mosas wrote: On Fri, 29 Oct 2004 John W.Krahn wrote : Prabahar Mosas wrote: specimen coding ** $value = 2422; $reg = '/\d/'; The slashes (/) are the delimiters for the match operator, they are not a part of the regular expression, just like the quotes (') delimit the string bu

Re: Printing to a file

2004-10-29 Thread John W. Krahn
Zeus Odin wrote: Charles Clarkson, Randall Schwartz, and John Krahn (I'm only naming three. You probably meant Randal Schwartz (one "l".) :-) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: each character in a string

2004-10-29 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi All, Hello, I have to write a code wherein I have to access each character in a string and compare it with '-' $_ = $seq1[0]; while(/./g) { if($1 eq '-') { $res1[0] .= '-'; ^^ } else { $res1[0] = "A"; ^ Is that supposed to be '.='

Re: Append on top

2004-10-29 Thread John W. Krahn
Jenda Krynicky wrote: From: [EMAIL PROTECTED] This is the way I would do it, however my code has been subject to criticism more that once in the past :) open (FILE, "; close (FILE); $new_data = "This is my new line that I am going to put at the top\n"; unshift (@file, $new_data);

Re: pattern matching

2004-10-30 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi All, Hello, I have to match patterns of the format string1>string2 where the strings 1 & 2 can contain alphabets,numbers and spaces. The string are separated by '>' sign. I wrote the following code for this. if(/([a-z]*[A-Z]*[0-9]*[\s]*)>([a-z]*[A-Z]*[\s]*[0-9]*)/g) {

Re: substr

2004-10-30 Thread John W. Krahn
[EMAIL PROTECTED] wrote: Hi All, Hello, I need to copy a substring in a string which is completely out of the primary string (in terms of the offset). substr does not allow me to do so. Do you mean like this: $ perl -le' $_ = q/abc/; substr( $_, 20 ) = q/def/; print' substr outside of string at -e

Re: pattern matching

2004-10-31 Thread John W. Krahn
Robert Citek wrote: On Saturday, Oct 30, 2004, at 20:52 US/Central, John W. Krahn wrote: [EMAIL PROTECTED] wrote: I have to match patterns of the format string1>string2 where the strings 1 & 2 can contain alphabets,numbers and spaces. The string are separated by '>' sign. I

  1   2   3   4   5   6   7   8   9   10   >