Re: Problem with regex

2014-10-06 Thread John Delacour
> On 6 Oct 2014, at 18:57, punit jain wrote: > > Thanks Paul. However I think I couldnot explain the problem. > > The issue is when I have mailid's as well as a part of input stream. > > Input stream ---> $str="ldap:///uid=user1,ou=People,o=test.com > ,a...@test.com

Re: Apologetic request for simple one-off script

2014-07-14 Thread John Delacour
On 14 Jul 2014, at 14:11, Shlomi Fish wrote: >> perldoc -f open > This is irrelevant. Two-args open is dangerous - always use three-args open: > > * http://perl-begin.org/tutorials/bad-elements/#open-function-style Who wrote that? Ah...a certain Shlomi Fish. open my $fh, "< $path"; # with o

Re: Apologetic request for simple one-off script

2014-07-14 Thread John Delacour
On 14 Jul 2014, at 05:39, Shlomi Fish wrote: > don't use two-args open perldoc -f open In the one- and two-argument forms of the call, the mode and filename should be concatenated (in that order), preferably separated by white space. You can--but shouldn't--

Re: Apologetic request for simple one-off script

2014-07-13 Thread John Delacour
On 13 Jul 2014, at 23:48, ESChamp wrote: > John Delacour has written on 7/13/2014 5:31 PM: >> >> On 13 Jul 2014, at 21:43, ESChamp wrote: >> >>> ...lastname firstname other other other ... emailaddress >>> >>> I wish to write a new file that c

Re: Apologetic request for simple one-off script

2014-07-13 Thread John Delacour
On 13 Jul 2014, at 21:43, ESChamp wrote: > ...lastname firstname other other other ... emailaddress > > I wish to write a new file that contains only the emailaddress field > contents. Here’s an easily-understood way of doing it: #!/usr/bin/perl use strict; while (){ chomp; @_ = split / /

Re: want to write to file in different format

2014-07-07 Thread John Delacour
On 7 Jul 2014, at 09:18, Sunita Pradhan wrote: > I have a file of contents: > --- > 1 6 > 2 7 > 3 8 > 4 9 > 5 10 > -- > I want a file with content: > > 1 2 3 4 5 > 6 7 8 9 10 Try this: #!/usr/local/bin/perl use strict; my (@col1, @col2); while () { chomp; my @words = spli

Re: one line script for word count

2014-06-30 Thread John Delacour
On 30 Jun 2014, at 20:05, Jim Gibson wrote: > Try this: > > $c = () = $line =~ /\b$w\b/g; Or, slightly less obscure: #!/usr/bin/perl use strict; my $line = "one potato two potato three potato four"; my @hits = $line =~ /potato/g; print scalar @hits; # => 3 #JD -- To unsubscribe, e-ma

Re: uninitialized error for hash printing

2014-06-22 Thread John Delacour
On 22 Jun 2014, at 21:01, Sunita Pradhan wrote: > I have following code for printing a simple hash. > > #!/usr/bin/perl -w > %hash = ("abc" => 123, "dfg" => 456, "xsd" => 34); > foreach $k (keys %hash){ > print "key $k:: value $hash{$k}\n"; > } > -- > Use of uninitialized

Re: Filtering Characters

2013-09-03 Thread John Delacour
On 3 Sep 2013, at 18:08, Matt wrote: > It skips to the next item in the while loop of the string begins with > # and works fine. I would also like to skip to the next item in the > loop if the string contains anything other then lowercase, > underscores, numbers, dashes, periods, and spaces. I

Re: grab pattern from start and end block

2013-07-12 Thread John Delacour
On 12/7/13 at 17:35, rvtol+use...@isolution.nl (Dr.Ruud) wrote: perl -0 -wple 's/^start\n(.*?)\nend\n/$_=$1;y{\n}{ };"$_\n"/emgs' Pure obfuscation! Why not keep things simple?! These stupid one-liners are a pain in the brain. #!/usr/bin/perl use strict; my @items; while (<>) { # or use a

Re: last

2013-06-24 Thread John Delacour
On 24/6/13 at 06:36, l...@yun.yagibdah.de (lee) wrote: while($test) { last if($foo) { print $bar; } else { print $test; } } doesn't work. Never mind “doesn’t work”; it doesn’t compile, because it is plain nonsense syntactically in whatever language. Compare your meaningless string with the

Re: how to retrieve the keys from hash in the sequence in which data is inserted

2013-04-23 Thread John Delacour
On 23/4/13 at 12:26, kavitahkulka...@gmail.com (kavita kulkarni) wrote: Can you help me in finding the most time effective way to retrieve the key-values from hash in the same sequence in which data is inserted into the hash. What about this? : #!/usr/bin/perl use strict; my @array; for ( {

Re: Line Endings

2013-02-24 Thread John Delacour
On 22/02/2013 18:08, Tiago Hori wrote: What I was wondering is: is there any way to force perl to use other line ending characters, like MacOS C The script below will first read the file for 1000 characters and set the value of $/. You can then loop through the lines in the usual way. #!/

Re: ISO decoding

2012-11-06 Thread John Delacour
On 06/11/2012 10:19, Gary Stainburn wrote: I'm writing a mail filter which accepts emails from our 'fax-to-email' gateway and I'm struggling to handle the input. I'm getting the following: Subject =?ISO-8859-1?B?UmVjZWl2ZWQgRnJ... Before you make a decision, read this from the MIME::Words pag

Re: Problem of general running of simple perl program.

2012-11-05 Thread John Delacour
On 05/11/2012 03:01, hong zeng wrote: When I run the send_email example on the website, I got some warning like this...I am really a beginner so I don't know where to find the answer so I post here. Thank you guys. ece% perl ./perl_test/send_email.pl Can't locate Email/MIME.pm in @INC (@INC con

Re: Learning CPAN

2012-10-06 Thread John Delacour
On 05/10/2012 04:14, Hal Wigoda wrote: Who uses newsgroups anynore? What reader application is the best for reading news groups? If your ISP doesn’t provide a news feed then you can read usenet groups in Google: If y

Re: CPAN question

2011-11-01 Thread John Delacour
At 18:38 + 1/11/11, Phil Dobbin wrote: I use the /usr/local/ version for everything & leave the other two to their intended purposes. My question is how do I configure CPAN to install into /usr/local/? The way I do it is simply: $ cd /usr/local/bin; sudo ./cpan No disrespect to Perlbrew

Re: How to put an AND in a regex?

2011-10-13 Thread John Delacour
At 10:33 + 13/10/11, Hamann, T.D. (Thomas) wrote: ...So I need something that does the equivalent of "Don't match this AND don't match this". Is this possible in a if loop, or should I use something else? for (qw (bcd 1num ASDSF two)){ print "$_\n" if !/^[0-9]/ and !/^[A-Z]+/; } JD -

Re: regex help

2011-10-10 Thread John Delacour
At 14:56 -0500 10/10/11, Chris Stinemetz wrote: Once I match HEH how can alter the program to print the contents that are in the two lines directly above the match? If it's only one instance you need to deal with then this should do the trick: #!/usr/bin/perl use strict; my @lines; while ()

Re: encoding and PDF::API2

2011-10-07 Thread John Delacour
At 09:54 +0200 7/10/11, marcos rebelo wrote: Unfortunatly someone has the code: < use encoding 'utf8'; > and now I get: ### $VAR1 = { 'Subject' => "\x{fffd}\x{fffd}my subject", 'CreationDate' => 'D:20111006161347+02\'00\'

Re: Matching Greek letters in UTF-8 file

2011-09-29 Thread John Delacour
At 17:29 -0300 29/9/11, Brian Fraser wrote: On Thu, Sep 29, 2011 at 4:03 PM, John Delacour wrote: Nitpick: Why the upper-case charset name? Uppercase is UTF-8-strict, while lowercase is the lax version that perl uses internally. Unless you are passing data from one perl program to

Re: Matching Greek letters in UTF-8 file

2011-09-29 Thread John Delacour
At 11:59 -0300 29/9/11, Brian Fraser wrote: On Thu, Sep 29, 2011 at 10:58 AM, John Delacour wrote: use encoding 'utf-8'; Nitpick: Please don't use this, as encoding is broken. use utf8; and use open qw< :std :encoding(UTF-8) >; should make do for a replacement. Ni

Re: Matching Greek letters in UTF-8 file

2011-09-29 Thread John Delacour
At 11:42 + 29/9/11, Hamann, T.D. (Thomas) wrote: I need to write a regex that matches any single Greek letter followed by a hyphen in a UTF-8 text file that is otherwise in English. How can I match the Greek alphabet (lower and upper case)? #!/usr/local/bin/perl use strict; use utf8; us

Re: Help, About Global variable.

2011-09-13 Thread John Delacour
At 16:39 -0500 13/09/2011, Chris Stinemetz wrote: From Learning Perl book: In some circumstances, $a and $b won't need to be declared, because they're used internally by sort. So if you're testing this feature, use other variable names than those two. The fact that use strict doesn't forbid the

Re: Help, About Global variable.

2011-09-13 Thread John Delacour
At 15:33 +0300 13/09/2011, Shlomi Fish wrote: ...For more information see: http://perl.plover.com/FAQs/Namespaces.html Useful article. Now can you explain why I get no error with this little routine? - #!/usr/local/bin/perl use strict; $a = 1; $b = 2;

Re: 3-argument open on STDIN

2011-08-17 Thread John Delacour
At 17:53 -0500 17/08/2011, Bryan R Harris wrote: How can I do a 3-argument open on STDIN? This doesn't work because the 3-argument open won't open STDIN when you tell it to open "-". ** @files = ("-"); for (@files) { print reverse readfile($_); } [...]

Re: using Perl, How to search for files in my computer

2011-06-12 Thread John Delacour
At 03:40 -0700 12/06/2011, eventual wrote: I've read perldoc File::Find but I dont understand. So If I wish to search for "mp3" in d:\ and all its sub-directories, and to print it out if found, How should I write? Just put the directory in $dir: #!/usr/local/bin/perl use strict; use File::

Re: solution for Regex

2011-06-11 Thread John Delacour
At 08:28 -0700 10/06/2011, Gurpreet Singh wrote: Correct me if i am wrong - $read = 0 unless /\s[A-Z]{3}:/; This might pick up wrong values also - since one of the DBLINKS data (the first record) might also get picked up - it should match this regex. Run my script with the data and see. $r

Re: solution for Regex

2011-06-10 Thread John Delacour
At 18:50 -0400 09/06/2011, Uri Guttman wrote: ...i don't know the data logic so i can't go further. at least you can run this and assign it to $read to remove redundancy. also you can declare $read here. my $read = s/^GENES//; No it isn't. If you don't "know the data logic" then i

Re: solution for Regex

2011-06-09 Thread John Delacour
At 10:48 +0200 09/06/2011, venkates wrote: I need to retrieve all the gene entries to add it to a hash ref. Your code is very fussy with all those substrings etc. What about something like this: #!/usr/local/bin/perl use strict; my $read = 0; my @genes; my %hash; while (){ chomp; $read =

Re: Relative URIs in served pages

2011-06-05 Thread John Delacour
At 22:33 -0400 04/06/2011, Brandon McCaig wrote: On Fri, Jun 3, 2011 at 1:14 PM, John Delacour wrote: I made it clear that I am serving the page dynamically from cgi-bin. Here is an example: That part is irrelevant though because the image file is loaded by the user agent AKA Web browser

Re: Relative URIs in served pages

2011-06-03 Thread John Delacour
At 12:11 -0400 03/06/2011, Brandon McCaig wrote: It would probably help if you could show us a simple example of what you're trying and what is wrong with it. :)... For example, if the current Web page is http://foo/bar/baz.html I made it clear that I am serving the page dynamically from cgi

Relative URIs in served pages

2011-06-01 Thread John Delacour
I have a script in cgi-bin which gathers information from the user and replaces placeholders in a pre-written html page with the data collected via a different html interface. Since the script needs to run from various servers I don't want to use absolute URIs for the images, css file etc. a

Re: Alternative to goto

2011-04-14 Thread John Delacour
At 23:00 +0300 14/04/2011, Shlomi Fish wrote: In Perl, I don't encourage people using goto statements, and I did not find a use for them in Perl, yet. But I don't rule out that they have legitimate use in other languages... int alloc_stuff(struct_t * * ref) { Let's stick to Perl and stop bo

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

2011-04-14 Thread John Delacour
At 13:39 +0300 12/04/2011, Shlomit Afgin wrote: I need to write regular expression that will capitalize the first letter of each word in the string. Word should be word that her length is greater or equal to 3 letters exclude the words 'and' and 'the'. I tried: $string = lc($string); $string

Re: help with array elements

2011-03-12 Thread John Delacour
At 03:14 -0500 12/03/2011, Uri Guttman wrote: this replaces the entire if/else statement: $hash{$item}++ ; ...it is a standard perl idiom you need to know so you don't waste code like that. Nice! so #!/usr/local/bin/perl use strict; my %hash; my @array = split //, 12342312111467; f

Re: assigning hash key to reference of array question

2011-02-28 Thread John Delacour
At 22:33 + 28/02/2011, Rob Dixon wrote: The complete program is below. HTH, Rob use strict; use warnings; my %HoA; while ( ) { my ($swit, $server, $ip_range) = split; my ($b_real_ip, $b_ip, $e_ip) = $ip_range =~ /(\d+\.\d+\.\d+\.)(\d+)-\1(\d+)/; for my $byte ($b_ip .. $e_ip)

Re: string substitution command question

2011-02-26 Thread John Delacour
At 12:57 -0800 26/02/2011, Richard Green wrote: > What is $gene_id? Are you by any chance using '$' at the beginning of your search pattern instead of the end? I have $ to designate the end of the row $gene_id $gene_id designates $gene_id period. > Why are you escaping the quote marks?

Re: string substitution command question

2011-02-26 Thread John Delacour
At 12:06 -0800 26/02/2011, Richard Green wrote: chr1ucscexon226488874 226488906 0.00 - . gene_id "NM_173083:12345"; transcript_id "NM_173083:12345"; chr1ucscexon226496810 226497198 0.00 - . gene_id "NM_173083:12345";

Re: Attachment in Excel format?

2011-02-07 Thread John Delacour
At 15:38 -0800 06/02/2011, David Newman wrote: Having the CSV output appear in the message body is a problem for the nontechnical audience that will receive this message. Why not just zip it? Archive::zip ? JD -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional command

Re: Text Manipulation

2011-02-07 Thread John Delacour
At 14:22 +0200 07/02/2011, Shlomi Fish wrote: Hi John, a few comments on your code. Actually, see perldoc perlrun - http://perldoc.perl.org/perlrun.html - by giving -p and -i (untested) you can replace the contents of a file "in-place". untested?! Why don't you test it before recommending

Re: Text Manipulation

2011-02-07 Thread John Delacour
At 07:11 -0800 05/02/2011, zavierz wrote: Here's code which was suggested to me, but when I execute it I'm returned to the command line and nothing happens: #!/usr/bin/perl s/^(Article\s+[0-9]+\s+\N*\S)/\\subsection*{$1}/gm I called this script "Article" and saved it as article.pl The usa

Re: Renaming with a specific spec

2011-02-04 Thread John Delacour
At 13:00 -0500 04/02/2011, Uri Guttman wrote: HP> Yet they seem to be carefully avoided. That is what I nearly always HP> use. Is there some reason to avoid `//' as delimiters? [ I really object to the backtick being used instead of an opening quote mark. The only possiblt excuse for i

Re: regular expression for special html characters

2011-02-03 Thread John Delacour
At 18:52 +0800 03/02/2011, Jeff Pang wrote: 2011/2/2 Shlomit Afgin : > I tried to convert html special characters to their real character. > For example, converting    ”      to     "   . > > I had the string > $str = "“ test ” ÈÒÈÂÔ†¢ª > The string contain also Hebrew letters. Could E

Re: how do make certain that no input (keyboard + mouse paste) is outside of 7-bit ASCII in a perl script?

2011-02-02 Thread John Delacour
At 17:08 -0800 01/02/2011, Kenneth Wolcott wrote: how do make certain that no input (keyboard + mouse paste) is outside of 7-bit ASCII in a perl script? The regular expression means that from the beginning to the end of the (chomped) input is either nothing or a string containing only charac

Re: problem getting multiple values returned from a subroutine

2011-02-02 Thread John Delacour
At 10:51 -0800 01/02/2011, loan tran wrote: I'm having problem getting multiple values returned from a subroutine. Thanks in advance for pointers. If you want help with a problem you should present the problem as simply as possible in a runnable form and not require your helpers to wade thr

Re: date handle

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

Re: doubt in substring

2011-01-15 Thread John Delacour
On 15 January 2011 07:52, Emeka wrote: > # perl -le '$str = "the cat sat on the mat";print substr( $str, 4, -4 )' > Can't find string terminator "'" anywhere before EOF at -e line 1. > > rmicro@RMICRO-PC C:\Program Files\xampp > # > > It failed to work for me. Why? Because you can't use single

Re: Return value from function

2011-01-13 Thread John Delacour
At 02:34 -0500 13/01/2011, shawn wilson wrote: I dig what you're saying about always using return. However I don't (have never used / seen) a case where a sub returns last expression. An example maybe? #!/usr/local/bin/perl use strict; use feature qw(say); say &SUB(); sub SUB { my $word = "

Re: Moving through tree's using LWP

2011-01-12 Thread John Delacour
At 12:52 +0200 12/01/2011, Shlomi Fish wrote: http://search.cpan.org/~jfearn/HTML- Tree-4.1/lib/HTML/Element.pm#$h-%3Etag%28%29_or_$h-%3Etag%28%27tagname%27%29 (sorry for the broken link). Links won't break in proper mailers if you enclose them in <>

Re: calculate average

2011-01-10 Thread John Delacour
At 18:16 -0800 07/01/2011, S.F. wrote: I have a data file with n columns and r row. The first 3 columns and the first 5 rows are: 2 3 1 1 6 X 4 0 X X 8 X 5 X 5 The "X" means missing. How could I write a script to calculate the average by column and replace "X" with the average? There must be

Re: problems hashing

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

RE: Getting LineFeed for Excel within q quoted field

2011-01-06 Thread John Delacour
At 11:55 -0600 06/01/2011, David Waner wrote: >From: John Delacour [mailto:johndelac...@gmail.com] >#!/usr/bin/perl use strict; my $csv="temp.csv"; open CSV, ">$csv"; >print CSV qq~1,2,"3\n4\n5"\n6,7,8~; For something that should have been rela

Re: Getting LineFeed for Excel within q quoted field

2011-01-05 Thread John Delacour
At 17:56 -0600 04/01/2011, Wagner, David wrote: I am generating an CSV and want a couple of fields to have soft returns in them. I went into Excel and added a couple of soft returns to a couple of different fields and then saved the modified file back to a CSV. If you run this script you wi

Re: 1st line of perl script

2011-01-04 Thread John Delacour
At 01:09 -0500 04/01/2011, George Worroll wrote: On 1/4/11 12:33 AM, Sunita Rani Pradhan wrote: Perl script works without the first line ( perl Interpreter : #! /usr/bin/perl) . What is the real use of this line ? This line does not through any error on Windows where , this path

Re: parsing data from txt file

2010-12-24 Thread John Delacour
On 24 December 2010 14:49, Jugurtha Hadjar wrote: > I rewrote your code and at the very beginning, just before any variable was > /used/ [i.e, just after "use strict", I added > > > # Intialization begins > > my $cell        =''; > my $filename    =''; If you're going to an empty value (which is