Re: $? $! ??????????????

2009-12-22 Thread John W. Krahn
Aimee Cardenas wrote: Ok, All, Hello, I'm a little confused. How does your outputs from die and print differ when you put either $! or $? at the end of the statement? I've been using $! at the end of my die statements and am afraid that I've been unknowingly not using the correct syntax

Re: Regexp to remove spaces

2009-12-20 Thread John W. Krahn
Shawn H Corey wrote: sftriman wrote: I use this series of regexp all over the place to clean up lines of text: $x=~s/^\s+//g; $x=~s/\s+$//g; $x=~s/\s+/ /g; in that order, and note the final one replace \s+ with a single space. Basically, it's (1) remove all leading space, (2) remove all

Re: Faster way to do a regexp using a hash

2009-12-20 Thread John W. Krahn
sftriman wrote: I've been wondering for a long time... is there a slick (and hopefully fast!) way to do this? foreach (keys %fixhash) { $x=~s/\b$_\b/$fixhash{$_}/gi; } So if $x=this could be so cool and $fixhash{could}=would; $fixhash{COOL}=awesome; $fixhash{beso}=nope;

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread John W. Krahn
Steve Bertrand wrote: Hi everyone, Hello, I'm reviewing a script I wrote that I use against one of my modules. The script takes an optional param at the command line. Although I am seriously reviewing my options for better and smarter ways to utilize command line args, I'm curious as to why

Re: Perlcritic complains about assignment within conditional

2009-12-15 Thread John W. Krahn
Steve Bertrand wrote: John W. Krahn wrote: Steve Bertrand wrote: if ( $month !~ m{ \A \d{4}-\d{2} \z }xms ) { print \nInvalid date parameter. Must be supplied as '-MM'\n\n; exit; You exit the program if $month is not equal to a seven character string. ehhh.. *scratching head

Re: Windoze Woez

2009-12-12 Thread John W. Krahn
Parag Kalra wrote: Hello All, Hello, This works on Linux - perl -e 'foreach (Sugar,Sex,Simplicity,Sleep,Success,Smoking) { print I am only addicted to - 'Shekels' \n if ($_ =~ /^s.*/i) }' This works on Windoze - perl -e foreach (Sugar,Sex,Simplicity,Sleep,Success,Smoking) { print 'I am only

Re: Windoze Woez

2009-12-12 Thread John W. Krahn
Parag Kalra wrote: On Sat, Dec 12, 2009 at 1:55 AM, John W. Krahn jwkr...@shaw.ca wrote: Parag Kalra wrote: This works on Linux - perl -e 'foreach (Sugar,Sex,Simplicity,Sleep,Success,Smoking) { print I am only addicted to - 'Shekels' \n if ($_ =~ /^s.*/i) }' This works on Windoze - perl

Re: Showing errors with user input

2009-12-10 Thread John W. Krahn
Adam Jimerson wrote: On Dec 7, 12:43 pm, g...@lazymountain.com (Greg Jetter) wrote: On Sunday 06 December 2009 10:24:31 am Adam Jimerson wrote: I am working on a registration page and there for want it to show the user errors it has found with their input. I have two subroutines in my code,

Re: Feedback, please

2009-12-10 Thread John W. Krahn
Shawn H Corey wrote: Steve Bertrand wrote: You can replace them all with this: my $station = $channels{ $opt_s }; my $station = $channels{ $opt_s } || help(); my $station = $channels{ $opt_s } or help(); Or: ( my $station = $channels{ $opt_s } ) || help(); John -- The programmer is

Re: matching an element from one array to another

2009-12-09 Thread John W. Krahn
Noah wrote: Hi there, Hello, I am hoping to figure out the best Way to write something. I have two arrays @previous_hostnames and @hostnames. I want to figure out if there is at least one matching element in @previous_hostnames that is found in @hostnames. my $found = map { my $x = $_;

Re: matching an element from one array to another

2009-12-09 Thread John W. Krahn
Rafa? Pocztarski wrote: I forgot to cc: the list... 2009/12/10 Noah noah-l...@enabled.com: I am hoping to figure out the best Way to write something. Â I have two arrays @previous_hostnames and @hostnames. I want to figure out if there is at least one matching element in @previous_hostnames

Re: passing Hash to subroutine help please

2009-12-08 Thread John W. Krahn
Jeff Pang wrote: Noah: sub exiting { my ($hostname, %login) = @_; Passing arguments like this has no such problem. But you'd better pass the hash as a reference to the subroutine. exitint($hostname, \%login); sub exiting { my $hostname = shift; my %login = %{+shift}; What is

Re: how to tr this?

2009-12-07 Thread John W. Krahn
Xiao Lan (小兰) wrote: Hello, Hello, I have a text whose content is like: aaaa bbbbaa aaxxxbb bb776yhghhaa I want to switch all aa and bb. I can handle this use regex: s/aa|bb/$ eq 'aa'?'bb':'aa'/ge; But how to use 'tr' doing that? $ perl -e' my @data = qw/ aaaa

Re: I want to know the reason

2009-12-05 Thread John W. Krahn
Parag Kalra wrote: Hello All, Hello, This code is working: #!/usr/bin/perl use warnings; use strict; You should include those two pragmas to let perl help you find mistakes in your code. 2 my @column_names=(A..ZZ); Why are you creating an array with 702 entries when you are

Re: How much time my Perl script is taking

2009-12-05 Thread John W. Krahn
Parag Kalra wrote: Hello All, Hello, I am looking for a simple way to determine the time taken by any Perl script. A simple method would be to put this line somewhere in your program: END { warn time - $^T, seconds elapsed\n } A specific module to determine the time of execution will

Re: newline regexes

2009-12-04 Thread John W. Krahn
jackassplus wrote: I am trying to remove single newlines but not double newlines. for instance say I have the following: Name:\nMy Name\n\nAddress:\n123 Anywhere St\n\nAbout Me:\nSome text that\nhas some newlines that\nI want to be rid of\n\nThe End\n I want to get rid of all of the newlines

Re: newline regexes

2009-12-04 Thread John W. Krahn
Shawn H Corey wrote: jackassplus wrote: I am trying to remove single newlines but not double newlines. for instance say I have the following: Name:\nMy Name\n\nAddress:\n123 Anywhere St\n\nAbout Me:\nSome text that\nhas some newlines that\nI want to be rid of\n\nThe End\n I want to get rid of

Re: do something after time expired

2009-11-30 Thread John W. Krahn
David Schmidt wrote: 2009/11/30 Jay Savage daggerqu...@gmail.com: Either way, you should be able to use the built-in functions to accomplish your task. See the docs for sleep(), alarm(), and select() for more info. Sorry for the bad explanation of my problem. Yes my program has to continue

Re: die unless match is successful

2009-11-29 Thread John W. Krahn
raphael() wrote: Hi, Hello, I want the below if loop to end if it cannot find any match print the die message. However it just exit without hitting my die As you can see in the code below I have tried many foolish ways to make the script say that it cannot find the number searched in while

Re: reference to anonymous array, references last element instead??

2009-11-28 Thread John W. Krahn
Mark_Galeck wrote: Why does $foobar = \(foo, bar); print $$foobar; print bar ?? Thank you for any insight. Mark Because \(foo, bar) is really (\foo, \bar) and the comma operator in scalar context will return the last item listed so: $foobar = \(foo, bar); Is just: $foobar = \bar;

Re: Autovivification of hash from an array

2009-11-28 Thread John W. Krahn
Jeremiah Foster wrote: Hi there! Hello, This may or may not be a beginners question. If not, please let me know where I ought to post. :-) I have a data structure, a simple array. It is made up of sections of files I have slurped; sub _build_packages { use Perl6::Slurp; Do you

Re: a simple question about the line

2009-11-27 Thread John W. Krahn
Majian wrote: Hi, all : Hello, I have a problem about the lines of the file , like this : cat test 12 23 34 45 56 67 78 ... == I want to display like this : 1223 3445 5667 It means the next line is after the last line . How do it by the Perl ? $ echo 12 23 34 45 56

Re: Regex to get last 3 digits of a number.

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Yonghua Peng wrote: --- On Tue, 24/11/09, Shawn H Corey shawnhco...@gmail.com wrote: From: Shawn H Corey shawnhco...@gmail.com Subject: Re: 答�: Regex to get last 3 digits of a number. To: gaochong zjgaoch...@gmail.com Cc: 'John W. Krahn' jwkr...@shaw.ca, 'Perl

Re: a match question

2009-11-24 Thread John W. Krahn
Orchid Fairy (À¼»¨ÏÉ×Ó) wrote: Hi, Hello, # perl -le '$_=aXXXb; print one word is $1 while(/(X*)/g);' one word is one word is XXX one word is one word is what are the three empty values in the output? The pattern X* can match zero characters. $ perl -le'$_=aXXXb; print one word is

Re: a match question

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Also: $ perl -le '$_=aXXXb; @captured = $_ =~ m{ (X*) }gmsx;print captured: , join( , ,@captured), ' captured: , XXX, , @captured = $_ =~ m{ (X*) }gmsx; Is usually written as: @captured = /X*/g; John -- The programmer is fighting against the two most destructive

Re: a match question

2009-11-24 Thread John W. Krahn
Shawn H Corey wrote: Jim Gibson wrote: On 11/24/09 Tue Nov 24, 2009 4:42 PM, Orchid Fairy (À¼»¨ÏÉ×Ó) practicalp...@gmail.com scribbled: On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey shawnhco...@gmail.com wrote: It seems to be picking up an extra empty string after a non-zero length

Re: Regex to get last 3 digits of a number.

2009-11-23 Thread John W. Krahn
shadow52 wrote: Hey everyone, Hello, I am trying to get just the last 3 numbers from the following number from perl using regexs but I have not had no success so I was hoping that I could get a little help on this. I just ordered the regex book from oreilly so that hopefully in the future I

Re: the question of one program

2009-11-19 Thread John W. Krahn
Shlomi Fish wrote: On Thursday 19 Nov 2009 16:54:00 gaochong wrote: Now I have see the following page ,but I have some question and need help . http://www.cpan.org/authors/id/S/SU/SUJAI/Process-Detail-0.1.pl the second , @array=split(/([A-Z]+(_|[A-Z])+\=.[^A-Z]+)/,$_); also the re

Re: Is unlink() supposed to provide an error message on failure?

2009-11-18 Thread John W. Krahn
David Christensen wrote: beginners: Hello, Is unlink() supposed to provide an error message on failure? Yes. All Perl functions that interact with the underlying system will set $! on failure. ($! is the same as errno in C.) man 3 errno man 2 unlink John -- The programmer is

Re: how to implement a long connection to tcp server

2009-11-18 Thread John W. Krahn
Orchid Fairy (À¼»¨ÏÉ×Ó) wrote: Hello, Hello, After making a connected socket to a tcp server, how to implement the read/write more than once? for example: 1) make socket connection 2) write a command to socket 3) read the result from remote server 4) write another command to socket 5) read

Re: mkdir in the mounted partition£¬please help me£¬thanks

2009-11-17 Thread John W. Krahn
gaochong wrote: #!/usr/bin/perl -w #Auther:gaochong use strict; my @list = (3 .. 9); my @FA=(FA0001..FA2000); sub mk_fa { my ($f) = @_; foreach my $p (@list) { mkdir /data$p/NRU/$f,0755 or warn mkdir /data$p/NRU/$f err:$!; symlink

Re: join lines

2009-11-15 Thread John W. Krahn
Jackie Jackie wrote: I tried to adapt this code to obtain my desired output. I need help. My logic is While if lines are not empty {do} if lines are empty {do} While if lines are not empty {do} else for empty lines{do} I am new to programming. I have problem with logic and syntax. So please

Re: redirecting to a file in perl

2009-11-13 Thread John W. Krahn
Dermot wrote: 2009/11/13 Subhashini subhashinibasavar...@gmail.com: I am doing a coversion on french to english words.I have installed the dictionary and i could use it on my command prompt using the following command. dict -d fd-fra-eng bonjour This is a french to english coversion dict

Re: push coomand on hash variables

2009-11-12 Thread John W. Krahn
Anant Gupta wrote: .. use strict; .. my %hash; my $abc; my $count; while(defined($ARGV[$count])) { push(@hash{$abc},$ARGV[$count]); } Can't i use this The error is Type of arg 1 must be array not hash element ... @hash{$abc} is a hash slice. You probably want @{$hash{$abc}}. John

Re: push coomand on hash variables

2009-11-12 Thread John W. Krahn
Anant Gupta wrote: .. use strict; .. my %hash; my $abc; my $count; while(defined($ARGV[$count])) { push(@hash{$abc},$ARGV[$count]); } @ARGV gets its values from the command line so all its elements should be defined, unless you are using delete() on one of its elements. You are not

Re: check a string against a array

2009-11-10 Thread John W. Krahn
rithu wrote: Hi, Hello, I'm an oracle user. One of my implementation needs a little bit of perl usage. i've an array(@hexa_tableau) which contains restricted hexadecimal characters and a string which is converted into hexadecimal. while ((@carac) = $sel-fetchrow_array) {

Re: splitting and replacing characters

2009-11-09 Thread John W. Krahn
rithu wrote: Hi, Hello, Please help me to split a string as follows.. my $line = abcdefghijkl the expected output should be like: ab ef ij The logic is like alternate 2 characters should be removed $ perl -le' my $line = abcdefghijkl; my @data = unpack (a2x2)*, $line; print for

Re: Data Conversion ?

2009-11-07 Thread John W. Krahn
Nathan Gibbs wrote: How would I get the length of a string as returned by length () into a 4 byte unsigned integer in network byte order my $length = pack 'N', length $string; John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human

Re: must satisfy _unknown_ number of regexp patterns

2009-11-06 Thread John W. Krahn
tom smith wrote: On Fri, Nov 6, 2009 at 12:15 AM, John W. Krahn jwkr...@shaw.ca wrote: Michael Alipio wrote: if I have a script that accepts any combination of the 5 or maybe even more options, say, option1, option2, option3... Now, after collecting the options, for each option

Re: __DATA__ in command line

2009-11-05 Thread John W. Krahn
À¼»¨ÏÉ×Ó wrote: Hello, Hello, doesn't one-liner Perl command support __DATA__ handler? No. It only works in an actual file located on a real file system. Just found this: # perl -e 'while(DATA){ print } __DATA__ abc 123 def ' run without any output. You could always do it like

Re: must satisfy _unknown_ number of regexp patterns

2009-11-05 Thread John W. Krahn
Michael Alipio wrote: Hi, Hello, if I have a script that accepts any combination of the 5 or maybe even more options, say, option1, option2, option3... Now, after collecting the options, for each option, there is a corresponding regexp pattern. I will then build an if statement, where the

Re: Optimizing File handling operations

2009-11-05 Thread John W. Krahn
Parag Kalra wrote: Hey Folks, Hello, I Frequently use perl to process 2 files line by line. Most of the times I compare two files line by line and check if one line is same to corresponding line of other file, or if one line is substring of other line etc and many more operations. The

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
Majian wrote: Hi ,all : Hello, I want to know if there is a way in which I can randomnize(?) the content in an array. In this example : my @array = ('uriel', 'daniel', 'joel', 'samuel'); Now what I want is create a process so every time I print the array it prints one element from the

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
Philip Potter wrote: 2009/11/3 John W. Krahn jwkr...@shaw.ca: Majian wrote: my @array = ('uriel', 'daniel', 'joel', 'samuel'); Now what I want is create a process so every time I print the array it prints one element from the array . I wrote it like this : #!/usr/bin/perl -w use strict

Re: How do I pick one random element from an array?

2009-11-03 Thread John W. Krahn
Majian wrote: Thanks all . Hello, But I found an another question : If I wrote this script like this : #!/usr/bin/perl use warnings; use strict; while (DATA){ @lines = $_; You are assigning one scalar value to the whole array the array will only ever have one element in it. You

Re: Problem about substitution..

2009-11-03 Thread John W. Krahn
tom smith wrote: On Mon, Nov 2, 2009 at 7:41 PM, Remy Guo rollingst...@gmail.com wrote: i've got problem when trying to perform a substitution. the text file i want to process is like this: ... XX { ABDADADGA afj*DHFHH } (a123) XXDFAAF { af2hwefh fauufui } (b332) ... i want to match

Re: Increment Operator (++) question in Perl

2009-11-03 Thread John W. Krahn
Majian wrote: Hi ,all: Hello, When I test the increment operator in Perl and find a question : The question is : #!/usr/bin/perl use warnings; my $i = 1; print ++$i + ++$i, \n; The above code prints out the answer 6 . But in the other language the anser is 5 , And the lesson to

Re: Problem about substitution..

2009-11-03 Thread John W. Krahn
tom smith wrote: On Tue, Nov 3, 2009 at 4:33 PM, tom smith climbingpartn...@gmail.comwrote: Thanks for the tips! More comments below. I saw it written the other way somewhere, and I thought it looked cleaner. I'll do it your way from now on. if ($line =~ /\((.*?)\)/) { $line

Re: Regex to array woes

2009-11-03 Thread John W. Krahn
Brent Clark wrote: Hiya Hello, I was hoping that someone would be kind to help me. I have a string like so : Haresources : 10.203.4.5, Interfaces : 10.203.4.5 10.203.4.7 Im trying to get the ip's after Interfaces into an array, but for the likes of me, im just not getting it right. This

Re: Regex to array woes

2009-11-03 Thread John W. Krahn
John W. Krahn wrote: Brent Clark wrote: I was hoping that someone would be kind to help me. I have a string like so : Haresources : 10.203.4.5, Interfaces : 10.203.4.5 10.203.4.7 Im trying to get the ip's after Interfaces into an array, but for the likes of me, im just not getting it right

Re: foreach loop

2009-11-02 Thread John W. Krahn
Anant Gupta wrote: Hello, Hello, In the foreach loop, without going to the beginning of the loop, i want to get the next iteration of data. How do i get it. eg use strict; open(FILE,abc.txt) or die CAnnot open; my @lines=FILE; foreach my $line(@lines) { if($lin =~ m/something/) {

Re: foreach loop

2009-11-02 Thread John W. Krahn
Philip Potter wrote: 2009/11/2 Thomas Bätzler t.baetz...@bringe.com: while( my $line = $file ){ snip } Won't this loop terminate early if there is a blank line or a line containing only '0'? If I do a readline loop I always do: while (defined ($line = $file)) Is there something magical

Re: Problem about substitution..

2009-11-02 Thread John W. Krahn
Remy Guo wrote: hi folks, Hello, i've got problem when trying to perform a substitution. the text file i want to process is like this: ... XX { ABDADADGA afj*DHFHH } (a123) XXDFAAF { af2hwefh fauufui } (b332) ... i want to match the content in the parenthesis (a123 and b332, here)

Re: Emulating Sort through Perl

2009-10-30 Thread John W. Krahn
Parag Kalra wrote: Hello Folks, Hello, This is my first post here. I am trying to emulate Linux 'sort' command through Perl. I got following code through Internet to sort the text file: # cat sort.pl my $column_number = 2; # Sorting by 3rd column since 0-origin based my $prev = ; for (

Re: Emulating Sort through Perl

2009-10-30 Thread John W. Krahn
Shawn H Corey wrote: Parag Kalra wrote: # cat sort.pl my $column_number = 2; # Sorting by 3rd column since 0-origin based my $prev = ; for ( map { $_-[0] } sort { $a-[1] cmp $b-[1] } map { [$_, (split)[$column_number]] } map { [$_, (split)[$column_number]] . $_ } ) { print

Re: OOB and dispatch table

2009-10-30 Thread John W. Krahn
Steve Bertrand wrote: Hi all, Hello, Within a CGI environment, I'm trying to do a dispatch table test, but can't figure out how to call the coderef as a method. Here is the working code. I'll describe what doesn't work afterwards: sub perform_find { my $self= shift; my

Re: Fasta format !!

2009-10-29 Thread John W. Krahn
Jyoti wrote: Hello All, Hello, I just want help to open and read a file. I have to make a script so that it should open and read a file which is in fasta format. I have done something with subroutine but getting some errors. May be everyone do not know the fasta format Fasta format have

Re: split n characters into n chunks

2009-10-25 Thread John W. Krahn
Michael Alipio wrote: Hi, Hello, How do I split a word into n subsets? my $word = thequickbrown If I want three subsets I should be able to create: the heq equ upto own $ perl -le' my $word = thequickbrown; my $subsets = 3; print for $word =~ /(?=(.{$subsets}))/g; ' the heq

Re: split n characters into n chunks

2009-10-25 Thread John W. Krahn
Shawn H Corey wrote: John W. Krahn wrote: $ perl -le' my $word = thequickbrown; my $subsets = 3; print for $word =~ /(?=(.{$subsets}))/g; Getting up there but substr is still the fastest. #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; # Make Data::Dumper pretty $Data

Re: About the $nextline question ~~

2009-10-24 Thread John W. Krahn
Majian wrote: Hi,all: I have the text like this: xxx sum = 1, xx xx xx d_bits xxx xxx xx sum =0 xx xx xx d_bit xx My question is : How can I read the nextline after the d_bits if sum = 1? $ echo xxx sum = 1, xx xx xx d_bits x1xx x2xx xx sum =0 xx xx xx d_bit xx | perl

Re: Question about split

2009-10-23 Thread John W. Krahn
sanket vaidya wrote: Hi, Hello, Consider the code below: use warnings; use strict; my $string = '100955 BLow-Gomez,Joseph MMEX.AMER. QHUTC012'; my ($id) = split(/\s/,$string); print id = $id; Output: 100955 Now remove brackets surrounding $id like as under: use warnings; use strict;

Re: Convert Site Name to Dotted IP Address

2009-10-22 Thread John W. Krahn
Anant Gupta wrote: I wrote #!usr/bin/perl use Socket; use constant ADDR = 'www.google.com'; my $name=shift || ADDR; $packed=gethostbyname($name); $dotted-inet_ntoa($packed); print DOtted Address is $packed; but it is showing an error Bad argument length for Socket length in inet_ntoa ???

Re: Want to write a script to note specific IP addresses.

2009-10-22 Thread John W. Krahn
hongyi.z...@gmail.com wrote: On Thursday, October 22, 2009 at 15:08, mrdanwal...@gmail.com wrote: 2009/10/19 Hongyi Zhao hongyi.z...@gmail.com: I want to write a script to note specific IP Â addresses by appending the corresponding location informations. Â For I suggest you take a look at

Re: The Perl question of the here document

2009-10-21 Thread John W. Krahn
Majian wrote: Dear list: Hello, Sorry to distrub all . When I learned Perl on the book called Perl by example 4th Chinese Edition , I found there was an error on this book . There had a perl script writted by this : #!/usr/bin/perl

Re: How to set a proxy server.

2009-10-20 Thread John W. Krahn
Majian wrote: Dear list: Hello, I have a question on learning Perl . Please give me a help . The problem is : How can I split a string into chunks of size n bytes?Like this : #!/usr/bin/perl my $string = 1234567890abcdefghijABCDEFGHIJK; my $n = 2;# $n is group size. my @groups =

Re: Don't understand the errors

2009-10-19 Thread John W. Krahn
Harry Putnam wrote: John W. Krahn jwkr...@shaw.ca writes: Harry Putnam wrote: I'm not sure what these errors are telling me. The script is supposed to remove dups from .bash_history Wouldn't it be simpler to set HISTCONTROL to ignoredups: export HISTCONTROL=ignoredups Or: export

Re: Don't understand the errors

2009-10-18 Thread John W. Krahn
Harry Putnam wrote: I'm not sure what these errors are telling me. The script is supposed to remove dups from .bash_history Wouldn't it be simpler to set HISTCONTROL to ignoredups: export HISTCONTROL=ignoredups Or: export HISTCONTROL=ignoreboth but not operate on the last 12 lines...

Re: Need some explanation about these lines.

2009-10-16 Thread John W. Krahn
Raheel Hassan wrote: Thanks Arun and Rob, For example if this is the url then , https://localhost/Iv2/cbox/cbox-gui.pl?action=status my ($myself) = split(/\?/,$q-self_url); #$myself = https://localhost/Iv2/cbox-gui.pl my @base_url = split(/\//, $myself); # @base_url = {localhost, Iv2,

Re: Building a record on the fly via hash of hashes

2009-10-09 Thread John W. Krahn
Soham Das wrote: The Code: use strict; use warnings; use Tie::Handle::CSV; my $qbook = Tie::Handle::CSV-new('C:\Documents and Settings\Soham Das\Desktop\Quotes.csv',header=1); my $tradebook = Tie::Handle::CSV-new('C:\Documents and Settings\Soham Das\Desktop\Transactions.csv',header=1); my

Re: Need explanation about this code.

2009-10-08 Thread John W. Krahn
Raheel Hassan wrote: Hello, Hello, I have problems in understanding $...@$ use ? 1- my $ref = $$temp_sth - fetchall_arrayref({}); for(my $i=0; $i = $...@$ref}; $i++) { push(@$temp_table,$ref-[$i]);} $...@$ref} should be $#{$ref} or simply $#$ref And for(my $i=0; $i =

Re: adding populations

2009-10-08 Thread John W. Krahn
Jesus Fernandez wrote: Dear friends, Hello I'm trying to write a program that draws 5,000 numbers from an exponential distribution with mean 4N/k(k-1) N=10 000 k = 25 I have this: #!jesusafernandez/bin/perl use warnings; use strict; $k = 25; my $k = 25; $N = 1; my $N =

Re: Array's

2009-10-05 Thread John W. Krahn
Slick wrote: Just clarification. At this time I have not written any of my code (dont' know where to begin yet, however the website that I am looking at perl.begin.org seems to have diffrent methods for one item. I have seen @ for arrays written like this: @myarray ,but I have also seen an

Re: Change character code 160 to 32

2009-10-04 Thread John W. Krahn
Mike Flannigan wrote: I want to change character code 160 to character code 32 throughout a bunch of text files. I'm using this right now s/(.)/ord($1) == '160' ? chr(32) : $1 /eg; Here you are using the decimal numbers 160 and 32. This is very inefficient as you are searching for *every*

Re: decimal to binary?

2009-09-23 Thread John W. Krahn
Bryan R Harris wrote: I need to convert a number like this: -3205.0569059 ... into an 8-byte double (big and little endian), e.g. 4f 3e 52 00 2a bc 93 d3 (I just made up those 8 byte values). Is this easy in perl? Are long and short ints easy as well? $ perl -le'print unpack H*, pack d,

Re: decimal to binary?

2009-09-23 Thread John W. Krahn
Bryan R Harris wrote: John W. Krahn wrote: Bryan R Harris wrote: I need to convert a number like this: -3205.0569059 ... into an 8-byte double (big and little endian), e.g. 4f 3e 52 00 2a bc 93 d3 (I just made up those 8 byte values). Is this easy in perl? Are long and short ints easy

Re: matching multi occurrences or nothing

2009-09-19 Thread John W. Krahn
Noah Garrett Wallach wrote: Hi there Perl folks, Hello, Okay I am trying to figure this out. I am trying to match the following: $line = blahblahblah so I have the following line to match that $line =~ /((?:blah).*?){0,5}/; But I want to capture blah in a variable like $capture = $1;

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Steve Bertrand wrote: [ forgive me if it was sent twice. My first should be bounced as bad sender addr ]. Besides consistently forgetting how to properly spell ternary, I can't, for some reason, embed it's use into my brain no matter how much I read. It is borrowed from the C programming

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Philip Potter wrote: 2009/9/11 Uri Guttman u...@stemsystems.com: SB == Steve Bertrand st...@ibctech.ca writes: SB Besides consistently forgetting how to properly spell ternary, I SB can't, for some reason, embed it's use into my brain no matter how SB much I read. ternary op is an official

Re: text html from file to a scalar

2009-09-11 Thread John W. Krahn
John Plum wrote: HI Folk, Hello, May I introduce myself, John Plumridge, London, UK. John W. Krahn, Vancouver, Canada. - I'm still in awe of this whole creation we're in. Life? Nice to meet you. And very nice to meet you as well. I have a reason of course

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Philip Potter wrote: 2009/9/11 John W. Krahn jwkr...@shaw.ca: Philip Potter wrote: Does ?: guarantee that only one arm of its conditions will be executed? eg: # @_ has 3 elements $x = $flag ? shift : push; $ perl -e'$x = $flag ? shift : push;' Not enough arguments for push at -e line 1

Re: Ternary operator

2009-09-11 Thread John W. Krahn
John W. Krahn wrote: $ cat ternary-test.c #include stdio.h #include stdlib.h char *shift ( int *argc, char **argv ) { int i; char *temp = argv[ 0 ]; for ( i = 1; i *argc; ++i ) { argv[ i - 1 ] = argv[ i ]; } Opps, also need to adjust argc here: --*argc

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Philip Potter wrote: 2009/9/11 Steve Bertrand st...@ibctech.ca: Uri Guttman wrote: it is actually very simple to understand. the key point to knowing it and how to use it is that the 2 value expressions SHOULD NOT have side effects. that means changing something by assignment or other

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Philip Potter wrote: My point is that C documents its behaviour. It seems that Perl doesn't. man perl perldoc perl http://oreilly.com/catalog/9780596000271/ http://perldoc.perl.org/ perldoc -q Is there an ISO or ANSI certified version of Perl C's documentation is complete, C is a very

Re: Ternary operator

2009-09-11 Thread John W. Krahn
John W. Krahn wrote: Philip Potter wrote: 2009/9/11 Steve Bertrand st...@ibctech.ca: Uri Guttman wrote: it is actually very simple to understand. the key point to knowing it and how to use it is that the 2 value expressions SHOULD NOT have side effects. that means changing something

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Philip Potter wrote: 2009/9/11 John W. Krahn jwkr...@shaw.ca: Philip Potter wrote: My point is that C documents its behaviour. It seems that Perl doesn't. man perl perldoc perl http://oreilly.com/catalog/9780596000271/ http://perldoc.perl.org/ perldoc -q Is there an ISO or ANSI certified

Re: Ternary operator

2009-09-11 Thread John W. Krahn
Chas. Owens wrote: On Fri, Sep 11, 2009 at 09:56, John W. Krahn jwkr...@shaw.ca wrote: snip You can't tell everything about the language from the docs. Give me an example, I'll point you to the docs. (Have you read them all?) snip Okay, I will bite, where is it documented that (@a) x= 3

Re: Help Please

2009-09-10 Thread John W. Krahn
Jyoti wrote: Can someone explain me what these symbols mean in regular expression: my $trim = sub {local($_)=shift; $$_ =~ s/^\s*//; ^ means that you want to anchor the pattern at the beginning of the string in $$_. \s is a character class that matches the whitespace characters , \t,

Re: regexp question

2009-09-05 Thread John W. Krahn
Noah Garrett Wallach wrote: Okay I am having troubles finding this. in the perldoc modules. Is there a slicker way to write the following? if ($line =~ /(Blah1)(.*)/) { At this point we know that the pattern matched so $1 will contain the string Blah1 and $2 will contain a string of

Re: accessing chars in a string

2009-09-01 Thread John W. Krahn
Chuck Crisler wrote: How do I access specific character positions in a scalar string? In case it makes any difference, I specifically want to test the zeroth character. Something like the following. my $str = abc; if ($str[0] == '#') { do something... } if ( substr( $str, 0, 1 ) eq

Re: regex patern matching script

2009-08-30 Thread John W. Krahn
Tim Bowden wrote: I'm trying to extend (again) the short regex checking script given in Learning Perl (Absolutely fabulous book btw! Highly recommend it to anyone trying to learn Perl). I'd like to cycle through the memory variables printing those as well as $`, $ and $' as given in the

Re: Problem with sysread()

2009-08-22 Thread John W. Krahn
Peter Xu wrote: Hi, everyone, Hello, I've met some problem while practice my perl. It seems that in some condition, sysread() doesn't work? codes here: #!/usr/bin/perl -w use strict; $| = 1; open my $file, , test.txt or die; ## if these add

Re: Problem with sysread()

2009-08-22 Thread John W. Krahn
Peter Xu wrote: John W. Krahn wrote: perldoc -f sysread sysread FILEHANDLE,SCALAR,LENGTH,OFFSET sysread FILEHANDLE,SCALAR,LENGTH Attempts to read LENGTH bytes of data into variable SCALAR from the specified FILEHANDLE, using the system call read(2

Re: Precedence, and the ||= op again...

2009-08-17 Thread John W. Krahn
Steve Bertrand wrote: Hi all, Before chasing down and fixing an undef var earlier on in a trace path, I had the following code. I've finally gathered that fixing bugs and validating data upstream is far better than writing code to fix it later (of course, I had to write code to find out what

Re: 'Join' query

2009-08-07 Thread John W. Krahn
jet speed wrote: Hi, Hello, I would like to join the $abc with ':' the final desired output 1:2:3:4:5 #!/usr/bin/perl use strict; use warnings; my $abc = 1 2 3 4 5; my $out = join ':', $abc; print $out; executing the above, i get the same output 1 2 3 4 5, not sure were am going wrong.

Re: ||= operator

2009-08-07 Thread John W. Krahn
Admin wrote: Hi there, Hello, is there a page that explains the ||= operator and similar operators? google is not quite finding the special characters in the first 10 hits. $left ||= $right is just short for: $left = $left || $right and || is the logical OR operator. So if $left is

Re: Convert Array's into hashes

2009-08-06 Thread John W. Krahn
jet speed wrote: Hi, Hello, I have a query on converting arrays into hash.Please could you help me resolve the below. I have 2 arrays as bleow. @array1 = ( D_101 D_102 D_103 D_104); @array2 = (0 1 2 3); How can i convert both of these arrays into %hash, assigining the @array1 as keys

Re: FW: two questions

2009-08-06 Thread John W. Krahn
Bryan R Harris wrote: According to the FAQ you want to do it like this: s/^\s+//, s/\s+$// for $var; I can't find documentation of this notation anywhere, i.e. the comma between statements with a trailing for. John, where do you find all this cool stuff? This is just something you pick

Re: Comma operator

2009-08-06 Thread John W. Krahn
Bryan R Harris wrote: A question about the comma operator: (John and Chas deserve a rest from my questions, if they want it =). The binary comma operator in scalar context supposedly evaluates its left argument, throws that value away, then evaluates its right argument and returns that

Re: two questions

2009-08-05 Thread John W. Krahn
sys adm wrote: 1. why perl doesn't have a built-in strip() function? Why doesn't BASIC have built-in regular expressions? Why doesn't C have built-in strings? Why doesn't $LANGUAGE have built-in $FEATURE? Because that is the way the language was designed. each time I need to say $var

Re: two questions

2009-08-05 Thread John W. Krahn
Ed Avis wrote: sys adm sysadm at computermail.net writes: 1. why perl doesn't have a built-in strip() function? each time I need to say $var =~ s/^\s+|\s+//g to strip Good question. Perl 6 is fixing this by adding a 'trim' operator. The code I use is for ($var) { s/\A\s+//; s/\s+\z/ }

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