Re: Assigning to Substr
Rob, I want to check out the C code. Kindly mail it to my box. Have a great day! Emeka On Wed, Sep 7, 2011 at 8:00 PM, Rob Dixon rob.di...@gmx.com wrote: On 06/09/2011 13:04, Emeka wrote: Could someone explain what Perl does behind here? Assign to Substring.. substr($string, 0 , 5) = 'Greetings'; What do you want to know Emeka? There is no copy of the 'old' string, and substr behaves as documented. I have the C code of substr in front of me, but there is little else to say. Rob -- *Satajanus Nig. Ltd *
Re: Assigning to Substr
Rob, Which C file should check out? Emeka On Wed, Sep 7, 2011 at 8:08 PM, Emeka emekami...@gmail.com wrote: Rob, I want to check out the C code. Kindly mail it to my box. Have a great day! Emeka On Wed, Sep 7, 2011 at 8:00 PM, Rob Dixon rob.di...@gmx.com wrote: On 06/09/2011 13:04, Emeka wrote: Could someone explain what Perl does behind here? Assign to Substring.. substr($string, 0 , 5) = 'Greetings'; What do you want to know Emeka? There is no copy of the 'old' string, and substr behaves as documented. I have the C code of substr in front of me, but there is little else to say. Rob -- *Satajanus Nig. Ltd * -- *Satajanus Nig. Ltd *
Assigning to Substr
Hello All, Could someone explain what Perl does behind here? Assign to Substring.. substr($string, 0 , 5) = 'Greetings'; Regards, Emeka -- *Satajanus Nig. Ltd *
Re: Assigning to Substr
On Tue, Sep 6, 2011 at 1:19 PM, Shawn H Corey shawnhco...@gmail.com wrote: On 11-09-06 08:04 AM, Emeka wrote: Hello All, Could someone explain what Perl does behind here? Assign to Substring.. substr($string, 0 , 5) = 'Greetings'; Regards, Emeka It replaces the first 5 characters in $string with 'Greetings'. #!/usr/bin/env perl use strict; use warnings; my $string = 'Hello, world'; print $string\n; substr($string, 0 , 5) = 'Greetings'; print $string\n I asked what Perl does behind.. Is it an alias or what? I want internal detailsor something technical. Emeka __END__ Can also be written as: #!/usr/bin/env perl use strict; use warnings; my $string = 'Hello, world'; print $string\n; substr($string, 0 , 5, 'Greetings' ); print $string\n; __END__ -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early often. Eliminate software piracy: use only FLOSS. Make something worthwhile. -- Dear Hunter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
My Blog on Perl
Hello All, I have written a blog on Perl. It just has basic stuff. I would want you to go through and comment. That way it will help me to re-enforce what I have learned. Regards, Emeka
Fwd: My Blog on Perl
Hello All, I have written a blog on Perl. It just has basic stuff. I would want you to go through and comment. That way it will help me to re-enforce what I have learned. http://emekamicro.blogspot.com/2011/09/perl-here-i-come.html Regards, Emeka
Re: My Blog on Perl
Could you please post the link? My eyes are not as good as they once were and I have trouble see it from this distance. :) It was because of my poor sight too. http://emekamicro.blogspot.com/2011/09/perl-here-i-come.html -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early often. Eliminate software piracy: use only FLOSS. Make something worthwhile. -- Dear Hunter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: how to reverse string in perl?
$s =~ s{(\w+)}{scalar reverse($1)}eg; --- From Shlomi Fish perl -e'@words=split/\s+/,$ARGV[0];$_=reverse$_ for@words;print@words\n;' 'abcd efgh ijkl mnop' Shawn Corey print join ' ', map scalar reverse($_), split ' ', $str; Rob Dixon It is time we explain our codes ... I don't think that Narasimha will easily wrap his head around the first two. Regards, Emeka On Tue, Aug 30, 2011 at 4:30 PM, Rob Dixon rob.di...@gmx.com wrote: On 30/08/2011 16:02, Shawn H Corey wrote: On 11-08-30 05:38 AM, Narasimha Madineedi wrote: Hi all, I have a string like *abcd efgh ijkl mnop* i want to reverse the string like this *dcba hgfe lkji ponm* can any one tell me how to get the required output? thanks in advance.. perl -e'@words=split/\s+/,$ARGV[0];**$_=reverse$_ for@words;print@words\n;' 'abcd efgh ijkl mnop' Please remember that the default parameters for 'split' are almost always what is required. Splitting on /\s+/ is almost the same, but will return an empty initial field if the object string has leading whitespace. perldoc -f split says this: As a special case, specifying a PATTERN of space (' ') will split on white space just as split with no arguments does. ... A split on /\s+/ is like a split(' ') except that any leading whitespace produces a null first field. A split with no arguments really does a split(' ', $_) internally. So to extract all non-whitespace substrings from $ARGV[0] you should write split ' ', $string; Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: how to reverse string in perl?
$s =~ s{(\w+)}{scalar reverse($1)}eg; --- From Shlomi Fish perl -e'@words=split/\s+/,$ARGV[0]; $_=reverse$_ for@words;print@words\n;' 'abcd efgh ijkl mnop' Shawn Corey print join ' ', map scalar reverse($_), split ' ', $str; Rob Dixon It is time we explain our codes ... I don't think that Narasimha will easily wrap his head around the first two. (Once again Emeka, please bottom-post your responses and edit what you are quoting to what is relevant. Thanks :) I agree. It is a shame that senior and supposedly wise contributors here feel the need to boost their egos by posting obscure code. It is primarily a /beginners/ list, and should be treated as such. If you cannot teach then please hold off from showing us your wares. Perl already has a reputation for being incomprehensible without people who should know better proving that they are right. In particular I believe Perl should be treated as a programming language. Its flexibility allows a short script to be passed on the command line but, unless the question requires it, a perl -e script solution is an ugly way to express a solution. In particular it does not allow us to insist on the mandatory use strict; use warnings; header, and the consequent declaration of lexical variables. Rob OK: #!/usr/bin/env perl # prevent silly mistakes use strict; # issue warnings of possible mistakes use warnings; # read from Perl's data file handle, contents appear after __DATA__ while( my $line = DATA ){ # remove trailing newline # a newline is whatever is in $/, the $INPUT_RECORD_SEPARATOR # see `perldoc perlvar` and search for /\$INPUT_RECORD_SEPARATOR/ chomp $line; # split on whitespace, ignore leading and trailing empty elements # see `perldoc -f split` my @words = split ' ', $line; # do each word, one at a time foreach my $word ( @words ){ # reverse each word w/ Perl's reverse(). See `perldoc -f reverse` # since this is scalar context, the string is reversed # since $word is the `for` iteration variable, # any changes to it are stored back in @words $word = reverse $word; } # end foreach $word # use Perl's stringification to join the words back into a line # and print the original line and the modified one print $line : @words\n; } # end while DATA Awesome! Great Job! Thanks a million :( Regards, Emeka On Tue, Aug 30, 2011 at 6:38 PM, Shawn H Corey shawnhco...@gmail.comwrote: On 11-08-30 01:14 PM, Rob Dixon wrote: On 30/08/2011 17:54, Emeka wrote: $s =~ s{(\w+)}{scalar reverse($1)}eg; --- From Shlomi Fish perl -e'@words=split/\s+/,$ARGV[0];**$_=reverse$_ for@words;print@words\n;' 'abcd efgh ijkl mnop' Shawn Corey print join ' ', map scalar reverse($_), split ' ', $str; Rob Dixon It is time we explain our codes ... I don't think that Narasimha will easily wrap his head around the first two. (Once again Emeka, please bottom-post your responses and edit what you are quoting to what is relevant. Thanks :) I agree. It is a shame that senior and supposedly wise contributors here feel the need to boost their egos by posting obscure code. It is primarily a /beginners/ list, and should be treated as such. If you cannot teach then please hold off from showing us your wares. Perl already has a reputation for being incomprehensible without people who should know better proving that they are right. In particular I believe Perl should be treated as a programming language. Its flexibility allows a short script to be passed on the command line but, unless the question requires it, a perl -e script solution is an ugly way to express a solution. In particular it does not allow us to insist on the mandatory use strict; use warnings; header, and the consequent declaration of lexical variables. Rob OK: #!/usr/bin/env perl # prevent silly mistakes use strict; # issue warnings of possible mistakes use warnings; # read from Perl's data file handle, contents appear after __DATA__ while( my $line = DATA ){ # remove trailing newline # a newline is whatever is in $/, the $INPUT_RECORD_SEPARATOR # see `perldoc perlvar` and search for /\$INPUT_RECORD_SEPARATOR/ chomp $line; # split on whitespace, ignore leading and trailing empty elements # see `perldoc -f split` my @words = split ' ', $line; # do each word, one at a time foreach my $word ( @words ){ # reverse each word w/ Perl's reverse(). See `perldoc -f reverse` # since this is scalar context, the string is reversed # since $word is the `for` iteration variable, # any changes to it are stored back in @words $word = reverse $word; } # end foreach $word # use Perl's stringification to join the words back into a line # and print the original line and the modified one print $line : @words\n; } # end while DATA # The lines after the __DATA__ or __END__ # are read by the DATA file handle __DATA__ abcd efgh ijkl mnop -- Just my 0.0002
Re: CPAN on Windows Box
On Wed, Aug 24, 2011 at 12:31 AM, Jim Gibson jimsgib...@gmail.com wrote: On 8/23/11 Tue Aug 23, 2011 3:04 PM, Emeka emekami...@gmail.com scribbled: Hello All I tried this in order to install Perl-tk cpaninstall tk... But it failed to work. You need to let us know what exactly what went wrong when you tried to install the Tk module. It is next to impossible, otherwise. However, in this case, I can tell you that case matters, so try installing the Tk module: This is what I got rmicro@rmicro-PC ~ $ perl -MCPAN -e shell Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.9402) Enter 'h' for help. cpan[1] install Tk CPAN: Storable loaded ok (v2.21) Going to read 'C:\cygwin\home\rmicro\.cpan\Metadata' Database was generated on Thu, 25 Aug 2011 05:28:03 GMT Running install for module 'Tk' Cannot create directory C:\Program Files\xampp\perl\bin\.cpan\prefs cpan[2] And Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved. C:\Users\rmicroppm install http://www.bribes.org/perl/ppm/Tk.ppd Installing package 'http://www.bribes.org/perl/ppm/Tk.ppd'... mkdir C:\Program Files\xampp\perl\bin\.ppm/Tk-5944: Permission denied; Access is denied at C:/Program Files/xampp/perl/site/lib/PPM.pm line 333 Emeka cpan install Tk Then if that does not work, cut and past the relevant error messages into a message. Thanks. Good luck! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: CPAN on Windows Box
'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Finding dependencies for tixGlue.c Cannot find 'pTk/tixInt.h' assume made Cannot find 'pTk/tixImgXpm.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Finding dependencies for tkGlue.c Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tix.h' assume made Cannot find 'pTk/imgInt.h' assume made Cannot find 'pTk/tkWin.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Cannot find 'tkPlatDecls.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Finding dependencies for tkGlue_f.c Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Finding dependencies for tkWin32Dll.c Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Tests in PNG Tests in JPEG Tests in Event Writing Makefile for Tk Could not read 'C:\cygwin\home\rmicro\.cpan\build\Tk-804.029-3vXb8T\META.yml'. F alling back to other methods to determine prerequisites Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved. NMAKE : fatal error U1073: don't know how to make 'C:\Program' Stop. SREZIC/Tk-804.029.tar.gz nmake.exe -- NOT OK Warning (usually harmless): 'YAML' not installed, will not store persistent stat e Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible Failed during this command: SREZIC/Tk-804.029.tar.gz : make NO cpan[2] On Thu, Aug 25, 2011 at 7:29 AM, Emeka emekami...@gmail.com wrote: On Wed, Aug 24, 2011 at 12:31 AM, Jim Gibson jimsgib...@gmail.com wrote: On 8/23/11 Tue Aug 23, 2011 3:04 PM, Emeka emekami...@gmail.com scribbled: Hello All I tried this in order to install Perl-tk cpaninstall tk... But it failed to work. You need to let us know what exactly what went wrong when you tried to install the Tk module. It is next to impossible, otherwise. However, in this case, I can tell you that case matters, so try installing the Tk module: This is what I got rmicro@rmicro-PC ~ $ perl -MCPAN -e shell Terminal does not support AddHistory. cpan shell -- CPAN exploration and modules installation (v1.9402) Enter 'h' for help. cpan[1] install Tk CPAN: Storable loaded ok (v2.21) Going to read 'C:\cygwin\home\rmicro\.cpan\Metadata' Database was generated on Thu, 25 Aug 2011 05:28:03 GMT Running install for module 'Tk' Cannot create directory C:\Program Files\xampp\perl\bin\.cpan\prefs cpan[2] And Microsoft Windows [Version 6.0.6002] Copyright (c) 2006 Microsoft Corporation. All rights reserved. C:\Users\rmicroppm install http://www.bribes.org/perl/ppm/Tk.ppd Installing package 'http://www.bribes.org/perl/ppm/Tk.ppd'... mkdir C:\Program Files\xampp\perl\bin\.ppm/Tk-5944: Permission denied; Access is denied at C:/Program Files/xampp/perl/site/lib/PPM.pm line 333 Emeka cpan install Tk Then if that does not work, cut and past the relevant error messages into a message. Thanks. Good luck! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd * -- *Satajanus Nig. Ltd *
Re: CPAN on Windows Box
I am thinking that this may be from my make On Thu, Aug 25, 2011 at 8:02 AM, Emeka emekami...@gmail.com wrote: I added prefs folder inside .cpan It worked, that is I was able to download. However, I got some error message toward the end . Finding dependencies for strGlue.c Cannot find 'tclDecls.h' assume made Cannot find 'tclPlatDecls.h' assume made Finding dependencies for strcasecmp.c Finding dependencies for strdup.c Cannot find 'tkPort.h' assume made Finding dependencies for strtoul.c Finding dependencies for tclDecls_f.c Cannot find 'tclDecls.h' assume made Cannot find 'tclPlatDecls.h' assume made Finding dependencies for tixImgXpm_f.c Cannot find 'tixPort.h' assume made Cannot find 'tixInt.h' assume made Cannot find 'tixImgXpm.h' assume made Finding dependencies for tixInt_f.c Cannot find 'tixInt.h' assume made Finding dependencies for tixVars.c Cannot find 'tixInt.h' assume made Finding dependencies for tix_f.c Cannot find 'tix.h' assume made Finding dependencies for tkDecls_f.c Cannot find 'tk.h' assume made Finding dependencies for tkEvent_f.c Cannot find 'tclDecls.h' assume made Cannot find 'tclPlatDecls.h' assume made Finding dependencies for tkImgPhoto_f.c Cannot find 'tkPort.h' assume made Cannot find 'tkInt.h' assume made Finding dependencies for tkIntDecls_f.c Cannot find 'tkInt.h' assume made Cannot find 'tkIntDecls.h' assume made Finding dependencies for tkIntPlatDecls_f.c Cannot find 'tclDecls.h' assume made Cannot find 'tclPlatDecls.h' assume made Cannot find 'tkWinInt.h' assume made Cannot find 'tkIntPlatDecls.h' assume made Finding dependencies for tkIntXlibDecls_f.c Finding dependencies for tkInt_f.c Cannot find 'tkInt.h' assume made Finding dependencies for tkOption_f.c Cannot find 'tk.h' assume made Cannot find 'tkInt.h' assume made Finding dependencies for tkPlatDecls_f.c Cannot find 'tclDecls.h' assume made Cannot find 'tclPlatDecls.h' assume made Cannot find 'tkWin.h' assume made Cannot find 'tkPlatDecls.h' assume made Finding dependencies for tkProperty.c Cannot find 'tkPort.h' assume made Cannot find 'tkInt.h' assume made Finding dependencies for tk_f.c Cannot find 'tk.h' assume made Writing Makefile for Tk::pTk Writing Makefile for Tk::pod Checking if your kit is complete... Looks good Writing Makefile for Tk::demos Finding dependencies for X.xs Writing Makefile for Tk::X Finding dependencies for Xlib.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::Xlib Writing Makefile for Tk::Tixish Finding dependencies for Pixmap.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tixPort.h' assume made Cannot find 'pTk/tixInt.h' assume made Cannot find 'pTk/tixImgXpm.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Cannot find 'pTk/tixBitmaps.h' assume made Writing Makefile for Tk::Pixmap Finding dependencies for TixGrid.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tixPort.h' assume made Cannot find 'pTk/tixInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::TixGrid Writing Makefile for Tk::TextList Finding dependencies for Text.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::Text Finding dependencies for TList.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tixPort.h' assume made Cannot find 'pTk/tixInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::TList Finding dependencies for Scrollbar.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWin.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::Scrollbar Finding dependencies for Scale.xs Cannot find 'pTk/tkPort.h' assume made Cannot find 'pTk/tkInt.h' assume made Cannot find 'pTk/tkWinInt.h' assume made Writing Makefile for Tk::Scale Test Compile/Run config/has_png.c 'cl' is not recognized as an internal or external command, operable program or batch file. Building libpng.lib Note (probably harmless): No library found for -lm Note (probably harmless): No library found for oldnames.lib Note (probably harmless): No library found for kernel32.lib Note (probably harmless): No library found for user32.lib Note (probably harmless): No library found for gdi32.lib Note (probably harmless): No library found for winspool.lib Note (probably harmless): No library found for comdlg32.lib Note (probably harmless): No library found for advapi32.lib Note (probably harmless): No library found for shell32.lib Note (probably harmless): No library found for ole32.lib Note (probably harmless): No library
Image Modules
Hello All, I want to re-size and edit images. Which module would you advise? Emeka -- *Satajanus Nig. Ltd *
Re: loop break condition
Do we really need goto here? Emeka On Mon, Aug 22, 2011 at 10:03 AM, Shlomi Fish shlo...@shlomifish.orgwrote: Hi Alan, On Mon, 22 Aug 2011 13:10:05 +0530 Alan Haggai Alavi alanhag...@alanhaggai.org wrote: Hello Anant, i want to input some numbers via stdin in while loop.And loop should be broken if any nonnumeric character is entered.So how it can be checked. . my @ln; my $i=0; printGive line numbers you want to put into array.\n; while(1){ $ln[$i]=stdin; chomp $ln[$i]; if($ln[$i] =~ /\D/){ printIts not numeric value.\n; $i--; last; } $i++; } . In the above program, `$i` is mostly useless. The length of the array can easily be found out by using `scalar @ln`; Perl's `push` function can be used for pushing values into the array. There is no need for an index. The program can be rewritten as: use strict; use warnings; my @numbers; print Enter numbers:\n; while (1) { chomp( my $number = STDIN ); if ( $number =~ /\D/ ) { print $number is not a numeric value.\n; last; } else { push @numbers, $number; } } It's a good idea to always use last LABEL; instead of last; (as well as next LABEL; etc. in case more loops are added in between. So the program becomes: [CODE] use strict; use warnings; my @numbers; print Enter numbers:\n; STDIN_LOOP: while (1) { chomp( my $number = STDIN ); if ( $number =~ /\D/ ) { print $number is not a numeric value.\n; last STDIN_LOOP; } else { push @numbers, $number; } } [/CODE] See: http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-labels Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ What Makes Software Apps High Quality - http://shlom.in/sw-quality Live as if you were to die tomorrow. Learn as if you were to live forever. — http://en.wikiquote.org/wiki/Mohandas_Gandhi (Disputed) Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
GUI Module
Hello All, I am thinking of check out GUI ... so I would need to know where to start off. Is there a GUI module with Perl? Or am I going to pull one from web? Emeka -- *Satajanus Nig. Ltd *
Re: GUI Module
Perl-Tk ... That looks like what I am looking for, do I need to get is from reservoir or is it part of native modules I have Glade, but I have not really figured out how best to use it ... any example On Tue, Aug 23, 2011 at 12:26 PM, Chankey Pathak chankey...@gmail.comwrote: Use Glade, or Parade form builder. Perl-Tk On Tue, Aug 23, 2011 at 4:53 PM, Emeka emekami...@gmail.com wrote: Hello All, I am thinking of check out GUI ... so I would need to know where to start off. Is there a GUI module with Perl? Or am I going to pull one from web? Emeka -- *Satajanus Nig. Ltd * -- Regards, Chankey Pathak http://javaenthusiastic.blogspot.com -- *Satajanus Nig. Ltd *
Not walking together with Getopt Module
Hello All, Why shouldn't this work? use Getopt::Long; #$debug = 0; $result = GetOptions(age=i = $age); if ($age) {print Input age is $age years; } Emeka -- *Satajanus Nig. Ltd *
CPAN on Windows Box
Hello All I tried this in order to install Perl-tk cpaninstall tk... But it failed to work. Emeka -- *Satajanus Nig. Ltd *
I am going through github perl code
Hello All, What is the purpose of colon here ? sub pop : method { my $self = shift; my ($list) = $self-_prepare(@_); pop @$list; my $result = $list; return $self-_finalize($result); } Is this how to do function alias? sub sortBy {sort_by} # sub sort_by { my $self = shift; my ($list, $iterator, $context) = $self-_prepare(@_); my $result = [sort { $a cmp $iterator-($b) } @$list]; return $self-_finalize($result); } -- *Satajanus Nig. Ltd *
Re: Parsing a Text File using regex
John, Thanks for making things pretty simple for mere mortals .. chomp( my $raw_file = glob @ARGV ); I am of the view that glob sub is used for as tree (that is to get all the files in a folder and all its sub-folders. From the above, it seems like it could be used for something else... Someone should help me out here. Why are you copying the contents of @ARGV to a string and then globbing that string? If @ARGV contains more than one element then this will not work correctly. And why chomp() a string that will not contain newlines? What you want is something like: my $raw_file = $ARGV[ 0 ]; while(READFILE){chomp; $ln.=\n if /^\W.?+$/; if(/^\d{4}/){$yr=$;} # get the year if(/^[A-Z].+/){ $cat=$; # get the Category $cat=join,split /,/,$cat; # remove the comma in front $ln.= $yr: .$cat; # add both the year and Category } if(/\--.+/){$win=$`; # get the winner The use of $, $' and $` will slow down *ALL* regular expressions in the program. Better to just use capturing parentheses. if (/^(\d{4})/ ) { $yr = $1 } # get the year if ( /^([A-Z].+)/ ) { $cat = $1; # get the Category $cat = join , split /,/, $cat; # remove the comma in front $ln.= $yr: . $cat; # add both the year and Category } if ( /(.*?)\--.+/ ) { $win = $1; # get the winner What is the idiomatic Perl , $1 or $[`, ,'] ? And what makes [$, $', $`] to slow down *ALL* regular expressions in the program. -- *Satajanus Nig. Ltd *
Re: perl code to export data to excel
Vino, First learn how to use Excel with Perl. The below might be useful, please check them out. http://support.microsoft.com/kb/214797 http://www.ibm.com/developerworks/linux/library/l-pexcel/ Emeka On Thu, Aug 4, 2011 at 10:03 AM, VinoRex.E vino...@gmail.com wrote: Hi i am a beginner in Perl i have a pdb file containing the X,Y,and Z coordinates of atoms example given below. the data extends upto 1000 atoms and its coordinates. I need a perl program to export these data into excel worksheet into distinct columns and ROws. ATOM 1 N GLY A 2 1.888 -8.251 -2.511 1.00 36.63 N ATOM 2 CA GLY A 2 2.571 -8.428 -1.248 1.00 33.02 C ATOM 3 C GLY A 2 2.586 -7.069 -0.589 1.00 30.43 C ATOM 4 O GLY A 2 2.833 -6.107 -1.311 1.00 33.27 O ATOM 5 N GLY A 3 2.302 -6.984 0.693 1.00 24.67 N ATOM 6 CA GLY A 3 2.176 -5.723 1.348 1.00 18.88 C ATOM 7 C GLY A 3 0.700 -5.426 1.526 1.00 16.58 C ATOM 8 O GLY A 3 -0.187 -6.142 1.010 1.00 12.47 O ATOM 9 N LEU A 4 0.494 -4.400 2.328 1.00 15.00 N ATOM 10 CA LEU A 4 -0.835 -3.926 2.630 1.00 12.93 C ATOM 11 C LEU A 4 -0.868 -2.457 2.294 1.00 11.77 C ATOM 12 O LEU A 4 0.007 -1.688 2.694 1.00 12.22 O ATOM 13 CB LEU A 4 -1.151 -4.122 4.110 1.00 13.01 C ATOM 14 CG LEU A 4 -2.536 -3.681 4.562 1.00 12.36 C ATOM 15 CD1 LEU A 4 -3.577 -4.568 3.912 1.00 13.37 C ATOM 16 CD2 LEU A 4 -2.644 -3.766 6.052 1.00 12.77 C ATOM 17 N GLN A 5 -1.864 -2.055 1.522 1.00 10.93 N ATOM 18 CA GLN A 5 -2.101 -0.667 1.209 1.00 11.87 C ATOM 19 C GLN A 5 -3.075 -0.147 2.264 1.00 12.25 C ATOM 20 O GLN A 5 -4.200 -0.648 2.394 1.00 11.71 O ATOM 21 CB GLN A 5 -2.697 -0.574 -0.199 1.00 12.69 C ATOM 22 CG GLN A 5 -2.977 0.839 -0.692 1.00 18.30 C ATOM 23 CD GLN A 5 -1.725 1.720 -0.785 1.00 23.25 C ATOM 24 OE1 GLN A 5 -1.726 2.887 -0.412 1.00 29.61 O ATOM 25 NE2 GLN A 5 -0.612 1.212 -1.270 1.00 25.58 N ATOM 26 N VAL A 6 -2.637 0.814 3.049 1.00 10.73 N ATOM 27 CA VAL A 6 -3.466 1.409 4.078 1.00 10.95 C ATOM 28 C VAL A 6 -3.829 2.773 3.519 1.00 11.49 C ATOM 29 O VAL A 6 -3.054 3.742 3.589 1.00 9.28 O ATOM 30 CB VAL A 6 -2.688 1.567 5.433 1.00 13.22 C ATOM 31 CG1 VAL A 6 -3.664 2.085 6.488 1.00 13.44 C ATOM 32 CG2 VAL A 6 -2.109 0.228 5.926 1.00 11.70 C ATOM 33 N LYS A 7 -5.047 2.846 2.984 1.00 10.74 N ATOM 34 CA LYS A 7 -5.515 4.029 2.280 1.00 11.66 C ATOM 35 C LYS A 7 -5.445 5.308 3.081 1.00 11.12 C ATOM 36 O LYS A 7 -5.045 6.377 2.623 1.00 13.12 O ATOM 37 CB LYS A 7 -6.965 3.858 1.829 1.00 15.50 C ATOM 38 CG LYS A 7 -7.335 4.947 0.832 1.00 19.57 C ATOM 39 CD LYS A 7 -8.820 5.172 0.874 1.00 30.36 C ATOM 40 CE LYS A 7 -9.206 6.372 0.017 1.00 34.59 C ATOM 41 NZ LYS A 7 -10.630 6.633 0.157 1.00 39.48 N ATOM 42 N ASN A 8 -5.791 5.168 4.347 1.00 12.07 N ATOM 43 CA ASN A 8 -5.912 6.310 5.227 1.00 12.81 C ATOM 44 C ASN A 8 -4.602 6.946 5.628 1.00 12.09 C ATOM 45 O ASN A 8 -4.583 8.068 6.119 1.00 14.21 O ATOM 46 CB ASN A 8 -6.621 5.928 6.515 1.00 14.50 C ATOM 47 CG ASN A 8 -8.000 5.398 6.243 1.00 11.94 C ATOM 48 OD1 ASN A 8 -8.128 4.266 5.782 1.00 12.17 O ATOM 49 ND2 ASN A 8 -9.008 6.195 6.513 1.00 14.60 N ATOM 50 N PHE A 9 -3.511 6.229 5.464 1.00 10.86 N ATOM 51 CA PHE A 9 -2.264 6.756 5.951 1.00 12.74 C ATOM 52 C PHE A 9 -1.522 7.551 4.909 1.00 13.14 C ATOM 53 O PHE A 9 -0.921 7.001 4.018 1.00 15.38 O ATOM 54 CB PHE A 9 -1.417 5.568 6.457 1.00 14.18 C ATOM 55 CG PHE A 9 -1.761 5.002 7.835 1.00 13.51 C ATOM 56 CD1 PHE A 9 -2.871 5.453 8.570 1.00 12.16 C ATOM 57 CD2 PHE A 9 -0.921 4.025 8.380 1.00 13.88 C ATOM 58 CE1 PHE A 9 -3.107 4.934 9.847 1.00 13.66 C -- *Satajanus Nig. Ltd *
Re: open files in a directory
I guess that $sum should be my $sum before using it. Emeka On Mon, Aug 1, 2011 at 8:26 AM, John W. Krahn jwkr...@shaw.ca wrote: homedw wrote: hi all, Hello, i want to open some tha files in a directory, you can see the details below, #!/usr/bin/perl -w use strict; opendir (FH,'C:\Player'); chdir 'C:\Player'; for my $file(readdir FH) { open DH,$file; foreach my $line(DH) { while($line=~/a=(\d),b=(\w+)**/gi) { $sum+=$2-$1; } } } print $sum\n; I can't open the files in 'C:\Player', can you help me find out where the problem is? Use error checking on your system calls and let the system tell you what the problem is: #!/usr/bin/perl use warnings; use strict; opendir FH, 'C:\Player' or die Cannot opendir 'C:\\Player' because: $!; chdir 'C:\Player' or die Cannot chdir to 'C:\\Player' because: $!; for my $file ( readdir FH ) { open DH, '' $file or die Cannot open '$file' because: $!; foreach my $line ( DH ) { while ( $line =~ /a=(\d),b=(\w+)/gi ) { $sum += $2 - $1; } } } print $sum\n; __END__ John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Characters
Hello All, I would like to know how to access character from string lateral. Say I have $foo = From Big Brother Africa; I would want to print each of the characters of $foo on its own. In some languages string type is just array/list of characters. What is it in Perl? Emeka -- *Satajanus Nig. Ltd *
Re: Characters
John, Thanks and thanks :) Emeka On Mon, Aug 1, 2011 at 2:45 PM, John W. Krahn jwkr...@shaw.ca wrote: Emeka wrote: Hello All, Hello, I would like to know how to access character from string lateral. Say I have $foo = From Big Brother Africa; I would want to print each of the characters of $foo on its own. In some languages string type is just array/list of characters. What is it in Perl? A string. In Perl there are a few ways to do what you want: $ perl -le'my $foo = From Big Brother Africa; print for split //, $foo' F r o m B i g B r o t h e r A f r i c a $ perl -le'my $foo = From Big Brother Africa; print for $foo =~ /./sg' F r o m B i g B r o t h e r A f r i c a $ perl -le'my $foo = From Big Brother Africa; print for map substr( $foo, $_, 1 ), 0 .. length( $foo ) - 1' F r o m B i g B r o t h e r A f r i c a $ perl -le'my $foo = From Big Brother Africa; print for unpack (a)*, $foo' F r o m B i g B r o t h e r A f r i c a John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: Characters
Shlomi, Yea, that makes sense now. Emeka On Mon, Aug 1, 2011 at 2:52 PM, Shlomi Fish shlo...@shlomifish.org wrote: On Mon, 1 Aug 2011 13:49:22 +0100 AKINLEYE damola.akinl...@gmail.com wrote: my @characters = split /[\s]/, $foo; foreach my $letter(@characters ) { print $letter ; } or my @characters = split /[\s]/, $foo; print join(\n , @characters); That won't work because split/[\s]/ will split the string on any whitespace character into words that don't contain whitespace. As a result: shlomif:~$ perl -e 'print map { $_\n } split/[\s]/, Big Brother From Afr' Big Brother From Afr shlomif:~$ To convert a string to characters one can use split based on the empty regex, as Shawn showed: shlomif:~$ perl -e 'print map { $_\n } split//, Big Brother From Afr' B i g B r o t h e r F r o m A f r One can also access individual characters without splitting and populating an array using http://perldoc.perl.org/functions/substr.html . Here's a demo: #!/usr/bin/perl use strict; use warnings; my $s = Big Brother From Afr; foreach my $pos (0 .. length($s)-1) { my $c = substr($s, $pos, 1); print Character No. $pos = '$c'.\n } Untested code though. Untested indeed, and please avoid top posting. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Original Riddles - http://www.shlomifish.org/puzzles/ Comedy is simply a funny way of being serious. — http://en.wikiquote.org/wiki/Peter_Ustinov Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: Characters
Brian, Thanks for re-directing me back to my original question, and thank again for your well researched comment. I intend to dig deeper into string...hopefully know a bit of the internals. Emeka On Tue, Aug 2, 2011 at 3:39 AM, Brian Fraser frase...@gmail.com wrote: On Mon, Aug 1, 2011 at 9:14 AM, Emeka emekami...@gmail.com wrote: In some languages string type is just array/list of characters. What is it in Perl? There's no string type in Perl, internals notwithstanding. There's scalars, and a scalar can hold a string - If you care to dig deeper, that string is stored a series of octets, which may or may not be encoded in UTF-8. The problem with thinking of strings as arrays of characters is pretty simple: What's a character? õ, \x{F5} (LATIN SMALL LETTER O WITH TILDE) is a character, but what about õ, o\x{303}, (LATIN SMALL LETTER O, COMBINING TILDE)? What should string[0] return there? Can you get everyone to agree on that? : ) (For example, I had the displeasure of working with a fairly ancient version of Ruby where string[0] returned an octet, and there was no simple way of changing this. It was absolute hell. Never versions appear to be quite an improvement over that, though admittedly I haven't used those much) Also, this is a bit of a nitpick, but every solution shown so far is fairly worthless with Unicode data: Consider ȭ, o\x{303}\x{304}, LATIN SMALL LETTER O, COMBINING TILDE, COMBINING MACRON. Blindly doing /(.)/g on that will return a list with those three characters, and be mostly worthless. What you generally want is /(\X)/g, which will return the a single element list, that element being a string with all three components of the actual character (i.e. an extended grapheme cluster). Tom Christiansen explains this and much more in his Unicode Essentials talk, which you can read here: http://training.perl.com/OSCON2011/index.html and is probably the newest tour de force for almost any Perl programmer. -- *Satajanus Nig. Ltd *
Re: Characters
Rob, I have already picked up those functions. I think they are virtually the same in all languages. Thanks Emeka On Mon, Aug 1, 2011 at 6:21 PM, Rob Dixon rob.di...@gmx.com wrote: On 01/08/2011 13:14, Emeka wrote: I would like to know how to access character from string lateral. Say I have $foo = From Big Brother Africa; I would want to print each of the characters of $foo on its own. In some languages string type is just array/list of characters. What is it in Perl? Hi Emeka Perl is rich with string-handling operators. Take a look at perldoc perlfunc and look at Perl Functions by Category. Part of it reads Functions for SCALARs or strings chomp, chop, chr, crypt, hex, index, lc, lcfirst, length, oct, ord, pack, q//, qq//, reverse, rindex, sprintf, substr, tr///, uc, ucfirst, y/// Regular expressions and pattern matching m//, pos, quotemeta, s///, split, study, qr// So what you would ordinarily do in C by indexing an array of characters can have many better solutions in Perl. As has been mentioned by others, my @chars = split //, $string; will give you an array of one-character strings that you may be able to handle as if you were using a different language, but that is rarely the way to go if you are writing a Perl program. Perl regular expressions are very felxible and comprehensive, and you will find that most string operations are best expressed that way rather than using split, index, substr and so on. If you describe your goal then we would be able to help you better. Rob -- *Satajanus Nig. Ltd *
Access files in a folder
Hello All, I wanted to do this ... while(*.pl){ print $_; } I got BEGIN failed--compilation Am I using something that is old? Emeka -- *Satajanus Nig. Ltd *
Re: Access files in a folder
Thanks Rob ... It worked. Shawn thanks so much. I found out that the problem was from my little box Nanonote... It has a light weight Perl. When I switched to real thing it worked. Emeka On Sun, Jul 31, 2011 at 11:02 PM, Rob Dixon rob.di...@gmx.com wrote: On 31/07/2011 21:52, Emeka wrote: Hello All, I wanted to do this ... while(*.pl){ print $_; } I got BEGIN failed--compilation Am I using something that is old? There is nothing wrong with that. Please show your complete program - there must be something else in the file that is causing the compilation error. Rob -- *Satajanus Nig. Ltd *
Re: Access files in a folder
Shawn, Yours will print the content of each file... while mine will list only their names. Emeka On Sun, Jul 31, 2011 at 9:57 PM, Shawn H Corey shawnhco...@gmail.comwrote: On 11-07-31 04:52 PM, Emeka wrote: Hello All, I wanted to do this ... while(*.pl){ print $_; } I got BEGIN failed--compilation Am I using something that is old? Try: { local @ARGV = glob( '*.pl' ); while( ){ print $_; } } See: perldoc -f glob perldoc -f local perldoc perlvar and search for /\@ARGV/ -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early often. Eliminate software piracy: use only FLOSS. Make something worthwhile. -- Dear Hunter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: perl reference
Timo, One can even pass hash to a subroutine with a little trick, 'cos the default argument of a subroutine is an array @_. ** Check Example 2, in the code below. I think this trick is formalized by context rule. @voo = (boon, 12, man, 88); %coo = @voo; my $line = ; while(my ($key, $val) = each %coo){ $line.=$key = $val\n; } print $line; On Sat, Jul 30, 2011 at 2:17 AM, timothy adigun 2teezp...@gmail.com wrote: Hi Rajeev, with the link you provided, the statement In Perl, you can pass only one kind of argument to a subroutine: a scalar... a pointer (sort of). was made Reference sub-topic. So, it will not be a total truth that one can pass only one kind of argument to subroutine. Generally in perl the subroutrine default argument is an array @_, so that makes it possible to even pass arrays into subroutine! ** Check Example 1, in the code below. One can even pass hash to a subroutine with a little trick, 'cos the default argument of a subroutine is an array @_. ** Check Example 2, in the code below. Finally, I believe that one the main purpose of reference in perl is to help maintain the integrity of data passed to a subroutine. In Code Example 3 below, two arrays were passed to a sub., inside the sub. the two array merges to one, and lost identity, then printer with just one for loop. But one can keep these array intact, using reference as demonstrated in ** Code Example 4! To write Object oriented perl one might have to know reference well! Really it like pointer or passing reference using pointer in c++. CODES #!/usr/bin/perl -w use strict; ##Example 1# sub getter(@); #declaration of subroutine my $list=; my @arr=qw( 12 timo kunle 067 23.90 come_hm); sub getter(@){ # defination of subroutine foreach(@_){ $list.=$_\n; }return $list; } print getter(@arr); # print return value ## ##Example 2# my %hash=( fistname='larry', surname='wall', street='earth', value ='perl'); my $line=; sub getter_hash{ my %hash=@_; # the trick convert ur @_ to %hash while(my ($key,$val)=each %hash){ $line.=$key = $val\n; } return $line; } print getter_hash(%hash); ### ##Example 3# sub getter3(@); #declaration of subroutine $list=; my @arr1=qw( 12 timo kunle 067 23.90 come_hm); my @arr2=qw( US 23:46:13 local float GOP_DEBT -q34A); sub getter3(@){ # defination of subroutine foreach(@_){ $list.=$_\n; }return $list; } print getter(@arr1,@arr2); # print return value # ##Example 4# sub getter4($$); #declaration of subroutine my $count=0; my @arr3=qw( 12 timo kunle 067 23.90 come_hm); my @arr4=qw( US 23:46:13 local float GOP_DEBT -q34A); sub getter4($$){ # defination of subroutine my ($val1,$val2)=@_; foreach(@{$val1}){++$count; print $count:$_\n; }$count=0; foreach(@{$val2}){++$count; print $count:$_\n; } } getter4(\@arr3,\@arr4); # print return value Regards. On Fri, Jul 29, 2011 at 11:57 PM, Rajeev Prasad rp.ne...@yahoo.com wrote: Hello, from here: http://www.troubleshooters.com/codecorn/littperl/perlsub.htm i found: In Perl, you can pass only one kind of argument to a subroutine: a scalar. To pass any other kind of argument, you need to convert it to a scalar. You do that by passing a reference to it. A reference to anything is a scalar. If you're a C programmer you can think of a reference as a pointer (sort of). is that still true? date on website is 2003... thank you. Rajeev -- *Satajanus Nig. Ltd *
Re: perl reference
Timo, Noted!...However, one could work that into his code. CODE #!/usr/bin/perl -wl use strict; my @voo = (boon, 12, man); # note this 3 elements array die Must be even elements if @voo % 2; my %coo = @voo; while(my ($key, $val) = each %coo){ $line.=$key = $val\n; } print $line; Emeka On Sat, Jul 30, 2011 at 3:09 PM, timothy adigun 2teezp...@gmail.com wrote: Emeka, Yes in a way, but the point am making here is that one can also pass hash into a subroutine. Context is everything in Perl! Caution has to be taken however when converting array into hash. Hash elements must be even in number, whereas odd numbers of elements could be in array, one is passing to the hash, thereby an generating error! CODE #!/usr/bin/perl -wl use strict; my @voo = (boon, 12, man); # note this 3 elements array my %coo = @voo; my $line = ; while(my ($key, $val) = each %coo){ $line.=$key = $val\n; } print $line;# Oops Error On Sat, Jul 30, 2011 at 8:34 AM, Emeka emekami...@gmail.com wrote: Timo, One can even pass hash to a subroutine with a little trick, 'cos the default argument of a subroutine is an array @_. ** Check Example 2, in the code below. I think this trick is formalized by context rule. @voo = (boon, 12, man, 88); %coo = @voo; my $line = ; while(my ($key, $val) = each %coo){ $line.=$key = $val\n; } print $line; On Sat, Jul 30, 2011 at 2:17 AM, timothy adigun 2teezp...@gmail.comwrote: Hi Rajeev, with the link you provided, the statement In Perl, you can pass only one kind of argument to a subroutine: a scalar... a pointer (sort of). was made Reference sub-topic. So, it will not be a total truth that one can pass only one kind of argument to subroutine. Generally in perl the subroutrine default argument is an array @_, so that makes it possible to even pass arrays into subroutine! ** Check Example 1, in the code below. One can even pass hash to a subroutine with a little trick, 'cos the default argument of a subroutine is an array @_. ** Check Example 2, in the code below. Finally, I believe that one the main purpose of reference in perl is to help maintain the integrity of data passed to a subroutine. In Code Example 3 below, two arrays were passed to a sub., inside the sub. the two array merges to one, and lost identity, then printer with just one for loop. But one can keep these array intact, using reference as demonstrated in ** Code Example 4! To write Object oriented perl one might have to know reference well! Really it like pointer or passing reference using pointer in c++. CODES #!/usr/bin/perl -w use strict; ##Example 1# sub getter(@); #declaration of subroutine my $list=; my @arr=qw( 12 timo kunle 067 23.90 come_hm); sub getter(@){ # defination of subroutine foreach(@_){ $list.=$_\n; }return $list; } print getter(@arr); # print return value ## ##Example 2# my %hash=( fistname='larry', surname='wall', street='earth', value ='perl'); my $line=; sub getter_hash{ my %hash=@_; # the trick convert ur @_ to %hash while(my ($key,$val)=each %hash){ $line.=$key = $val\n; } return $line; } print getter_hash(%hash); ### ##Example 3# sub getter3(@); #declaration of subroutine $list=; my @arr1=qw( 12 timo kunle 067 23.90 come_hm); my @arr2=qw( US 23:46:13 local float GOP_DEBT -q34A); sub getter3(@){ # defination of subroutine foreach(@_){ $list.=$_\n; }return $list; } print getter(@arr1,@arr2); # print return value # ##Example 4# sub getter4($$); #declaration of subroutine my $count=0; my @arr3=qw( 12 timo kunle 067 23.90 come_hm); my @arr4=qw( US 23:46:13 local float GOP_DEBT -q34A); sub getter4($$){ # defination of subroutine my ($val1,$val2)=@_; foreach(@{$val1}){++$count; print $count:$_\n; }$count=0; foreach(@{$val2}){++$count; print $count:$_\n; } } getter4(\@arr3,\@arr4); # print return value Regards. On Fri, Jul 29, 2011 at 11:57 PM, Rajeev Prasad rp.ne...@yahoo.com wrote: Hello, from here: http://www.troubleshooters.com/codecorn/littperl/perlsub.htm i found: In Perl, you can pass only one kind of argument to a subroutine: a scalar. To pass any other kind of argument, you need to convert it to a scalar. You do that by passing a reference to it. A reference to anything is a scalar. If you're a C programmer you can think of a reference as a pointer (sort of). is that still true? date on website is 2003... thank you. Rajeev -- *Satajanus Nig. Ltd * -- *Satajanus Nig. Ltd *
Re: End-of-Marker
Rob, I checked perldoc , and it is pretty like reading Latin. I have been babied by Factor and co. Perl is something else(or should I say perldoc) , and as if that is not enough Google is not even finding it easy to search for stuff like $\ and $/. I am not infinitely lazy , and naturally I use Google to pick thing out easily. But when Google is not there to back me up I would only depend on your mercy and stackoverflow. Emeka On Thu, Jul 28, 2011 at 11:04 PM, Rob Dixon rob.di...@gmx.com wrote: On 28/07/2011 22:58, Emeka wrote: Rob, Thanks... Could you also explain ... $/? Emeka Please look at the documentation I have indicated in perldoc perlvar and come back to this list if you still have questions. Rob -- *Satajanus Nig. Ltd *
Re: Add line feed to line
Timo, #!/usr/bib/perl -w What is -w doing here? Emeka On Wed, Jul 27, 2011 at 9:59 PM, timothy adigun 2teezp...@gmail.com wrote: Tim, check this if it answers ur #1 question: #!/usr/bib/perl -w $\=\n; # with output record separator used you don't ve to use # $currentLine = $currentLine . \x{0A}; in ur code again my @arr=qw(item1 item2 item3); for(@arr){ print $_; # used $_ default argument # your items are separated without stress } Also, is there a better way to concatentate? You can use join like this: #!/usr/bib/perl -w use strict; my @arr=qw(item1 item2 item3); # u can put ur values into an array $arr=join *,*,@arr; # use join to ouput all values as a single scalar value # concatentate any separator u want, here I used , # in red colour print $arr; Thanks On Wed, Jul 27, 2011 at 9:03 PM, Tim Lewis twle...@sc.rr.com wrote: I found an answer that I thought I would share. I am using ActivePerl on Windows server 2003. ActivePerl translates 0A as CR\LF. The print statement was causing the issue. To stop this, I added binmode to my file handle: open(OUTPUT,$outputFileName); binmode OUTPUT; It works great now. Tim Lewis twle...@sc.rr.com wrote: I am attempting to add a line feed to the end of each line. When I do this, a carriage return is also added. My code lines are: $currentLine = $currentLine . \x{0A}; $finalOutput = $finalOutput . $currentLine; There has to be a way to do this. Also, is there a better way to concatentate? Thanks for any suggestions on this. Tim -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
End-of-Marker
Hello All, Could someone explain what $\ (end-of-marker) is? I need something detail with simple and complex examples? Emeka -- *Satajanus Nig. Ltd *
Re: Hanging out here
Goke, I based in Port-Harcourt. But I would very much like to be part of your meetup. Could you give me details and your schedule? Emeka On Sun, Jul 24, 2011 at 6:08 PM, Goke Aruna mykl...@gmail.com wrote: Nice to see enema in this list. Mekus ..are you based in lagos? Nice to share some thoughts about localizing perl community in Lagos Emeka emekami...@gmail.com wrote: Hello All, I have been here for a long time, but I just read stuff. I have not mustered enough energy to really check what Perl is all about until yesterday. Write-only, cowboy language or something pretty cool. I spent few hours going through learn.perl site stuff. I was really impressed. To me this is indeed a cool language. However, I noticed that among beginners here their concerns are mainly file manipulation, string manipulation and hash table. Shouldn't someone make a note with simple examples and put it on the internet? And I would want to see codes from experts here once in a while with their design's reasons. I have my own issues, and the most confusing part of Perl to me is this thing called context. Why do we have it in Perl? What is its gain to be language ? And another thing I am having issue to figure out is when it is really needed is \hoom, when hoom is a sub. I know from C , that if one is to use function as a parameter that it should be in the form of address. Apart from context, are there other hidden gems I need to know? I would want to also thank the author of Learning Perl the Hard Way (Allen B. Downey). I would want that book to be called Learning Perl the Soft Way. Finally , this group is awesome ... with kind experts and mentors. I really appreciate you help and time. Regards, Emeka -- *Satajanus Nig. Ltd * -- *Satajanus Nig. Ltd *
Hanging out here
Hello All, I have been here for a long time, but I just read stuff. I have not mustered enough energy to really check what Perl is all about until yesterday. Write-only, cowboy language or something pretty cool. I spent few hours going through learn.perl site stuff. I was really impressed. To me this is indeed a cool language. However, I noticed that among beginners here their concerns are mainly file manipulation, string manipulation and hash table. Shouldn't someone make a note with simple examples and put it on the internet? And I would want to see codes from experts here once in a while with their design's reasons. I have my own issues, and the most confusing part of Perl to me is this thing called context. Why do we have it in Perl? What is its gain to be language ? And another thing I am having issue to figure out is when it is really needed is \hoom, when hoom is a sub. I know from C , that if one is to use function as a parameter that it should be in the form of address. Apart from context, are there other hidden gems I need to know? I would want to also thank the author of Learning Perl the Hard Way (Allen B. Downey). I would want that book to be called Learning Perl the Soft Way. Finally , this group is awesome ... with kind experts and mentors. I really appreciate you help and time. Regards, Emeka -- *Satajanus Nig. Ltd *
Re: Twisting Text
Thanks all, however I have the below observations. John's version is not exact for heaves ,,, it has sashes which has two s more than heaves. Greg's Porter Stemmer looks cool but may not go deep. Example ... for trace . I may also get rat , race , ate ,eat, crate, but he base word is trace. I am checking on this game http://games.yahoo.com/game/text-twist-2, that is why I am looking at the algorithm to use to get this achieved. Regards, Emeka On Thu, Mar 24, 2011 at 1:41 AM, John W. Krahn rjwkr...@shaw.ca wrote: Emeka wrote: Hello All, Hello, I have a file containing dictionary of words ... I would like to play with the file in this way. Say I pick a word Heaves . I would like to find other words that could be derive from Heaves Have, Haves, eave , eaves, Has, see, eves and so on. I would not want to use brute force , I have an algorithm to speed things up. Can somebody help me? $ perl -lne' BEGIN { $word = lc Heaves; $pattern = qr/\A[$word]{1,@{[ length $word ]}}\z/; } print if lc =~ $pattern; ' /usr/share/dict/words | cat -n 1 A 2 As 3 Ashe 4 Av 5 Ava 6 Ave 7 Aves 8 E 9 Es 10 Eva 11 Eve 12 H 13 Haas 14 He 15 Hess 16 Hesse 17 S 18 Sasha 19 Se 20 Shea 21 V 22 Va 23 a 24 ah 25 aha 26 ahas 27 as 28 ash 29 ashes 30 ass 31 asses 32 assess 33 e 34 ease 35 eases 36 eave 37 eaves 38 eh 39 es 40 eve 41 eves 42 h 43 ha 44 hah 45 hahs 46 has 47 hash 48 hashes 49 have 50 haves 51 he 52 heave 53 heaves 54 hes 55 s 56 sash 57 sashes 58 sass 59 sasses 60 save 61 saves 62 sea 63 seas 64 see 65 sees 66 sh 67 shah 68 shahs 69 shave 70 shaves 71 she 72 sheave 73 shes 74 v 75 vase 76 vases 77 vs John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Twisting Text
Hello All, I have a file containing dictionary of words ... I would like to play with the file in this way. Say I pick a word Heaves . I would like to find other words that could be derive from Heaves Have, Haves, eave , eaves, Has, see, eves and so on. I would not want to use brute force , I have an algorithm to speed things up. Can somebody help me? Regards, Emeka -- *Satajanus Nig. Ltd *
Re: doubt in substring
*If I were beginning with Perl, I certainly would not practise in the console but get an editor, such as SciTE* Yes, I am. On Sat, Jan 15, 2011 at 3:04 PM, John Delacour johndelac...@gmail.comwrote: On 15 January 2011 07:52, Emeka emekami...@gmail.com 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 quotes for the script-string in Windows cmd.exe. If you must work in the command line, then you can either escape all your double quotes within the string or use qq~double-quoted string~ , where ~ can be any ascii character that is not in the string itself. perl -le $str = qq~the cat sat on the mat~; print substr( $str, 4, -4 ) If I were beginning with Perl, I certainly would not practise in the console but get an editor, such as SciTE http://www.scintilla.org/SciTE.html and run the scripts from the editor (using F5) in the case of SciTE. JD -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *
Re: doubt in substring
Setting environment for using XAMPP for Windows. rmicro@RMICRO-PC C:\Program Files\xampp # 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? rmicro@RMICRO-PC C:\Program Files\xampp # perl -v This is perl, v5.10.1 (*) built for MSWin32-x86-multi-thread Copyright 1987-2009, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using man perl or perldoc perl. If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. On Thu, Jan 13, 2011 at 3:16 PM, Shawn H Corey shawnhco...@gmail.comwrote: On 11-01-12 11:27 PM, Sunita Rani Pradhan wrote: I have a string as; $str = the cat sat on the mat . How the following command works substr($str , 4, -4) on the string ? What should be the output? TITS (Try It To See) perl -le '$str = the cat sat on the mat;print substr( $str, 4, -4 )' -- Just my 0.0002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early often. Eliminate software piracy: use only FLOSS. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- *Satajanus Nig. Ltd *