Re: about perl module uninstallation
On Jun 22, 3:32 pm, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: > Note: the CPAN Shell and the CPAN-PLUS Shell are not package managers, and > have no uninstall capability. Cpan-plus can uninstall, but only if you installed the module with cpan-plus originally. I thought that was one of the main benefits of cpanp over cpan (the command not the CPAN). Not that this necessarily helps here. @ Rajnikant - How did you install them and why do you need to remove them? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: about perl module uninstallation
On Jul 1, 12:22 pm, [EMAIL PROTECTED] (Randal L. Schwartz) wrote: > I tried not to have to explain all this in my previous post, but since > you challenged my brief explanation, here's the details, yet again. Please, > just trust me when I say things in the future. It's faster. :) For fun, I will try to translate this into English. On Jul 1, 12:22 pm, [EMAIL PROTECTED] (Randal L. Schwartz) **actually meant**: > In my first post, I was brief to the point of being misleading. I will now > overcompensate for this with a bit of arrogance and a final winning smile. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable in perl
On Tue Oct 14 2008 @ 3:58, Rob Dixon wrote: > Chas. Owens wrote: > > > > [...] if for some reason you don't have access to perldoc > > Are there any installations of perl that don't include the manual? In Debian (and so probably many of its children), perl-doc is a distinct package and not installed automatically when you install the perl package. Stupid, but true. pgpwMlrqVQW8g.pgp Description: PGP signature
Re: ignore directories with File::Find?
On Wed Oct 22 2008 @ 4:32, protoplasm wrote: > I ran find2perl to give me some output that I included below (in > Sub_directory). If I have no network shares mounted it runs fine. But > I have some shares mounted (sftp, or smb, etc.) via Nautilus, the > below script really takes a long time. It begins to search through > ~/.gvfs which is where Nautilus mounts user shares. How can I find a > particular directory while ignoring hidden folders like .gvfs? I don't have experience with shared filesystems, so John's answer may be far better. That said, when I want to ignore .svn subfolders, I do this at the start of the subrouting that I hand to File::Find: return $File::Find::prune = 1 if $_ eq '.svn'; HTH, T pgpfaDXPh8cB4.pgp Description: PGP signature
Re: Curly braces and the logic of PERL
On Mon Oct 27 2008 @ 5:05, Brian wrote: > An example of something confusing me is in the sample below > find sub { > return unless -f; > open my $FH, '<', $_ or die "Cannot open '$_' $!"; > while ( <$FH> ) { > /\Q$string/ && print $REPORT "$File::Find::name\n" and > return; > }}, '/test'; > > Why isn't the last line > }, '/test';} Does this make it any better? find sub { return unless -f; open my $FH, '<', $_ or die "Cannot open '$_' $!"; while ( <$FH> ) { /\Q$string/ && print $REPORT "$File::Find::name\n" and return; } # close the while loop }, '/test'; # close the sub and run the subroutine on the directory '/test' The first brace closes the while loop. The second closes the subroutine. The subroutine itself is an anonymous one with the directory to process placed immediately following. In a nutshell, instead of this: find( \&subroutine, '/test' ); you can write this: find sub { stuff; }, '/test'; Hope this helps, T pgpGz4ZdonQ25.pgp Description: PGP signature
Re: Curly braces and the logic of PERL
On Mon Oct 27 2008 @ 12:35, John W. Krahn wrote: > The fewer lines of code to read and/or write, the easier it is to spot > mistakes, the less chance for "action at a distance." I find that there's a point, however, where compression and understanding cross paths. After that, the fewer lines and less code only make for less meaning to me as I try desperately to figure out what the code does. Obviously when this happens depends a great deal on how much you know about the language in question - how many idioms you've absorbed, how many times you've used a certain trick, etc. pgpJPJ1kwgWIs.pgp Description: PGP signature
Re: debugger exiting
On Tue Nov 04 2008 @ 4:11, Rob Dixon wrote: > > Rob Dixon wrote: > If I had things my way there would never be any use of Perl as a command-line > tool. Isn't this throwing out the baby with the bathwater? Here's a random, real, recent example of why I'm not giving up Perl on the command line. I had to reformat a computer at work and as always I put a bunch of personal Perl scripts into $HOME/bin. The versions I had saved started with #!/usr/bin/perl, but I wanted them to use #!/usr/local/bin/perl (5.10 with added modules rather than Apple's default, system-wide version of 5.8.x). Why write, save and run a 10 line script when I can simply do this? perl -i.bak -pe 's{/usr/bin/perl}{/usr/local/bin/perl}' * You write as though our only options are "portraying Perl as a command-line tool" or never using it on the command line. I think that there's a lot of middle ground. (All of that said, I'm writing this email using vim & mutt, notwithstanding all the Apple-y gui goodness at my command. So, maybe I'm weird.) T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Cron environment for execution of Perl script
On Thu Nov 06 2008 @ 3:42, Wagner, David --- Senior Programmer Analyst --- WGO wrote: > I need an environment variable from my .profile on Solaris and having > troubles getting at it. I have a Perl script which executes fine outside of > cron and now am trying to do via cron. I wanted to stay away from a shell > script and was wondering what is the easiest way to get my .profile loaded, > so the Perl script can access the needed variable. Rather than try to source your entire profile, why not simply set the necessary environment variables in the Perl script itself, using the %ENV hash? See this post perhaps for some other tips (it's Solaris specific, which may help): http://www.perlmonks.org/?node_id=624540 T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Using perl in a Bash-script to extract IP-addresses?
On Sun Nov 09 2008 @ 1:31, JC Janos wrote: > I've read that Perl (which I don't know yet at all) is "best" for Text > processing like this. > > The thing is that I need to do this from within a Bash script, and > assign the comma-separated list to a variable in that Bash script. > > Can I even use Perl like this, from inside a Bash script? I can imagine two ways that you might do this, but neither one strikes me as a good idea. First, you might create a Perl one-liner that could be run just as is from within the shell script. Second, you could create a small, self-contained Perl script, then assign the output from that to a variable in the Bash script. Both alternatives seem error-prone and hackish to me. More importantly, if Bash is a requirement and you don't know any Perl, I can't quite see the value in adding Perl to your current problems. That said, Perl could do what you need to do here pretty easily. In the version below, I stuck the IP addresses into the same file (in the DATA section) for convenience, but it wouldn't be any harder if they were in a separate file. So maybe that's some incentive to learn Perl. Hope this helps, T #!/usr/bin/perl use strict; use warnings; my @addresses; while () { if ( /(!?\d+\.\d+\.\d+\.\d+(?:\/\d+)?)/ ) { push @addresses, $1; } } my $csv = join ",", @addresses; print "$csv"; __DATA__ 1.1.1.1 # comment A 2.2.2.2/29 # comment B !3.3.3.3 # comment C !4.4.4.4/28 # comment D -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Two questions about split and map in a cookbook recipe
Good morning, I'm using a recipe from The Perl Cookbook (11.10 for anyone browsing at home) to produce a record structure from items in a text file. The text file itself has a simple structure: field:value field:value field:value field:value field:value etc. That is, the records are separated by a blank line and they contain key/value pairs, joined by a colon. The code I'm working with is this: $/ = ""; while (<>) { my @fields = split /^([^:]+):\s*/m; shift @fields; push(@Array_of_Records, { map /(.*)/, @fields }); } It works well to produce an array of hashes, and I can manipulate it from there without trouble. However, I want to understand this section better. First question: why does the split command produce a leading null field? (My best guess is that the regex [^:]+ captures anything that is not a colon, and that includes a null field?!?) Second question: what is the map doing in the last line, and why is it written with // delimiters? (Best guess, it is including everything from fields within parentheses (forcing the items to be treated as a list?) and you can't use {} because of the outer {} to create the hash reference?!?) Sorry if this is very long. I wanted to make sure to include enough information to make the questions clear. Thanks in advance, Telemachus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Two questions about split and map in a cookbook recipe
On Mon Nov 17 2008 @ 10:21, John W. Krahn wrote: > Set paragraph mode. > >> while (<>) { > > Read a paragraph into $_. In your example a paragraph is: > > " field:value > field:value > field:value > > " > >> my @fields = split /^([^:]+):\s*/m; > > Since there are multiple lines in a paragraph they use /^/m to work on > one line at a time. That pattern splits into three fields, the field > before '([^:]+):\s*', which will be '' for the first line, the field > enclosed in parentheses '[^:]+', and the field after '([^:]+):\s*'. > > >> shift @fields; > > The first field is always empty so remove it. > > >> push(@Array_of_Records, { map /(.*)/, @fields }); > > Store the fields as a hash at the end of @Array_of_Records. The filter > /(.*)/ ensures that no newlines are included in the keys or values of > the hash. Thanks for your careful explanation. I was just in the process of writing that I had worked out that the map keeps newlines out. I'll push my luck and ask two further questions. First, what exactly is the "null field" at the start of my first line, or where does it come from? In the version you wrote of my data, you visualized it with a space, but it's not (normally) visible. (This may just be something very simple about computers and how they represent text that I don't know.) Second, if I know that my records only have newlines at the end of lines is there any larger advantage to using the map construct above instead of simply chomp @fields? (One advantage of chomp for me is that I'm in no danger of misunderstanding it later.) Thanks again, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: random
On Tue Nov 25 2008 @ 9:29, Sharan Basappa wrote: > Hi, > > Would like to know if perl has native (without using special modules) > for generating random numbers? Shawn already pointed you in the right direction, but here's a good tip. If you want to check if you something Perl-ish, try 'perldoc -q something'. That will search the Perl FAQ. perldoc -q rand (or 'random') would work nicely here. Hope this helps, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: random
On Tue Nov 25 2008 @ 12:45, Telemachus wrote: > If you want to check if you something Perl-ish Something clearly went wrong here. I got caught between "to check if you can do something with Perl" and "to check something Perl-ish." What I sent was neither. Feh. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: perl version for windows
On Tue Nov 25 2008 @ 3:27, Chas. Owens wrote: > On Tue, Nov 25, 2008 at 12:26, Rob Dixon <[EMAIL PROTECTED]> wrote: > > Chas. Owens wrote: > >> > >> I need to look up why they call apartments flats. > > > > 'Flat' came from old english 'flet', and that from old german 'flaz' and > > 'flezzi' meaning 'flat', 'level' and 'floor'. > > > > A flat is one level or floor of a building. > > > > Now tell me why you call flats apartments :) > > > > Rob > > > > It comes from the Latin word for separating, it refers to that fact > that it is one building separated into individual living areas. To check and raise Rob, I think you need to add "Now tell me why you people call the trunk of a car a boot." Or did I misunderstand the rules of the game? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to make two perl work together?
On Mon Dec 01 2008 @ 12:04, Chas. Owens wrote: > On Mon, Dec 1, 2008 at 08:23, Jeff Pang <[EMAIL PROTECTED]> wrote: > > > Message du 01/12/08 11:38 > >> De : "howa" > >> A : beginners@perl.org > >> Copie à : > >> Objet : How to make two perl work together? > >> > >> > >> Hello, > >> > >> I have one perl (5.10) installed by my Ubuntu 8.10, as this version of > >> Perl has > >> memory leak issue with regex, so I compile another one into /opt/ > >> perl5.8.9. > >> > > > > > > Oh really? I have used perl 5.10 for quite a while, didn't meet this > > problem. > > It looks like there is an issue in the compilation of regexes that leaks > memory: > > perl -le 'qr// while 1' > > There does seem to be a fix*. > > * http://www.gossamer-threads.com/lists/perl/porters/232045 The memory leak has been patched in Debian, so it *should* be patched in Ubuntu as well, I would think. http://packages.debian.org/changelogs/pool/main/p/perl/current/changelog#versionversion5.10.0-17 I can confirm that the memory leak is gone, because on my home Debian machine, there's no problem, but my Mac at work (where 5.10.0 is my own version), the memory leak still appears under the same conditions. Hope this helps, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with subroutines and reading/writing to file
On Mon Dec 01 2008 @ 7:13, blake askew wrote: > Thanks for the help John. I have made the changes you suggested and managed > to get everything working properly. One more question though that is > completely different, how do I allow users to specify switches on the > command line in any order to be used in my program. For example, I want the > syntax to be ./ipcheck.pl {options specified in any order}. I > know I can get the value for the ip using $ip=$ARGV[0] and port using > $port=$ARGV[1] but how would I get the remaining options? > > Example to help clarify: ./ipcheck 10.10.10.1 80 -n -a -r > where -n -a -r are options in no particular order, 10.10.10.1 is the ip and > 80 is the port. Check out Getopt::Long. It's a core module (that is, it's available with Perl itself - you don't need to install anything extra). perldoc Getopt::Long Hope this helps, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Good Resource (book) for RegEx
On Wed Dec 03 2008 @ 10:46, Rex wrote: > In order to ramp up quickly on the nitty-gritty of Regular Expressions > in Perl, what will be a good book to start with? I do have moderate > familiarity with RegEx, but am still not using all that Perl's RegEx > engine has to offer. Hence the question. > > Thanks, > Rex I'm a big fan of the (free) material available as part of perldoc. In addition to the basic reference, there are two tutorials (one more basic, the other more detailed). perldoc perlrequick perldoc perlretut perldoc perlre If you don't want to read these in a terminal, you can get pdf versions for printing here: http://perldoc.perl.org/ The book I see cited most often as a standard is Mastering Regular Expressions by Jeffrey Friedl. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how to use module when not installed by web-hosting company
On Mon Dec 08 2008 @ 7:17, itshardtogetone wrote: > Hi, > My website is hosted in 110mb.com and they do not have this module installed > Algorithm::Numerical::Shuffle qw /shuffle/; > So what can I do to use that module. > Thanks You should be able to create a directory in your $HOME, say /myPerlModules and then add a line like this at the top of your script (after use warnings and use strict) use lib '/home/username/myPerlModules'; use Algorithm::Numerical::Shuffle qw/shuffle/; # Do stuff See here for more on this: http://perlmonks.org/?node_id=128077#permission Hope this helps, T -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: inverting List::Compare
On Sat Jan 03 2009 @ 9:21, David Newman wrote: > On 1/2/09 5:22 PM, Rob Dixon wrote: > >> #!/usr/bin/perl -w > >> > >> use strict; > > > > You should also use the warnings pragma instead of the command-line switch. > > > > use warnings; > > OK. Why is this better? My understanding is that the pragma (use warnings;) is more flexible than -w. You can turn it off for specific blocks, for example, and it doesn't apply to modules or other files you load with 'use' or 'require'. See here for more: http://perldoc.perl.org/perllexwarn.html Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Was re: inverting List::Compare
On Sat Jan 03 2009 @ 11:00, John W. Krahn wrote: >>> David Newman wrote: >> I always found it "cleaner", and have heard others say it's preferable, >> to declare all variables at the top of the program (although admittedly >> I didn't do that even in this short script). > > It is always better to limit the scope of variables. If variables need > to be in file scope anyway then a few lines one way or the other > probably won't make that much difference. So, I'm curious about this now. I've also read the advice always to declare all variables at the top of the program (in C books, perhaps, or shell script books and tutorials?). But Perl-centered advice always seems to be the other way around: limit the scope of variables; declare things only when you need them (and in the smallest scope possible). The second approach makes sense to me, and I use it, but I'm wondering what motivated the original approach. Was it simply a wrong-headed attempt to be "logical" - all the variables go here, then main, then the functions, etc.? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Neater way to declare variables
On Thu Jan 08 2009 @ 11:56, Taylor, Andrew (ASPIRE) wrote: > # In a number of places, I have code that looks like the following. > > > > my $default_type; > > > > if( $split_line[0] eq "DEFAULT_INPUT" ) > > { > > $default_type = "INPUT"; > > } > This works OK, but I'm trying to avoid declaring variables seperately > from assigning them (wherever possible), and trying to keep the size of > the script down without losing human legibility. You can use the statement modifier conditional form, in which case, the if follows the assignment. Many people find this easier to read for such a simple test: my $default_type = "INPUT" if $split_line[0] eq "DEFAULT_INPUT"; See here for more: http://perldoc.perl.org/perlsyn.html#Statement-Modifiers Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Passing info to a sub function
On Mon Jan 12 2009 @ 7:56, Mr. Shawn H. Corey wrote: > On Mon, 2009-01-12 at 18:40 -0600, Harry Putnam wrote: > > I'm in the middle of some administrative type of scripting and my > > skill level is pretty low. I ran up on a need to pass two different > > kinds of chunks of into to a sub function. > > See `perldoc perlsub` and search for /Pass by Reference/ > One other recommendation: if you are going to begin learning about references, I highly recommend the brief tutorial perlreftut. You can get it via Perl's internal documentation at perldoc perlreftut or if you prefer an online or PDF version, try here: http://perldoc.perl.org/perlreftut.html Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl Newbie question about upgrade from Perl 5.8.8 to 5.10
On Wed Jan 14 2009 @ 8:17, dolphin_sonar wrote: > Hi, > > I bought the O'Reilly 5th edition Learning Perl the other day and it's > great. I am new to programming and Perl as well. I do know my way > around Linux but I am having problems upgrading from the version that > was on my OS (Cent OS 5.2) to 5.10. I downloaded Perl 5.10 from > http://www.cpan.org/authors/id/R/RG/RGARCIA/perl-5.10.0.tar.gz, then > tar -xvzf perl-5.10.0.tar.gz the package in /usr/local/bin I then > followed the README guide that said to: > > ./Configure -des -Dprefix=$HOME/localperl > make test > make install > > Now, the first command was probably my mistake because I really have > no idea what that would do. In -Dprefix=$HOME/localperl, the variable $HOME is what you're not getting, I think. That configuration line means "build a new installation of Perl in my home directory and put it all into a folder called localperl." (Normally, the build would get put into the directory you choose, but then into bin/, lib, share/ and man/ directories there.) > I've also noticed that now there's a perl5.10.0 located in the /root/ > localperl/bin so I am sure it has something to do with the > above .Configure command. Can anyone give me some advice on how to get > 5.10 working? I feel like I am close, but nothing so far. Apparently, you were logged in as root when you built and installed this version of Perl. That was a mistake. You should be root as little as possible. (I can tell you were root since $HOME for root = /root. You configured it to be built in $HOME/localperl and it was.) In any case, I would recommend that you remove entirely the localperl/ directory in your root home directory, and then start again. Download the latest sources as a regular user, in your regular user's $HOME. Then build it and install it there. After that you should be able to invoke it with this shebang line: #!/home/username/localperl/bin/perl Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: need help on perl script
On Thu Jan 15 2009 @ 1:12, Kammen van, Marco, Springer SBM NL wrote: > Looking at all his posts below with the exact same format just different > questions... > > Is this guy for real... or is this a spam bot?? A real guy with a lot of homework? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Newbie question about variables, arrays and where they all go
On Sun Jan 18 2009 @ 10:59, dolphin_sonar wrote: >1 # When calling 'running_sum(5, 6);' the variable 'state @numbers' > receives those two >2 # parameters, (5 and 6), right? Then, the @numbers array also > copies/stores (5 and 6) >3 # into the special '( @_ )' variable as well, right? Also, line > 13 pushes '$number' into >4 # the '@numbers' array each time through the foreach loop, > right? Maybe I'm not understaning what you mean, but I think you're confused. The arguments to a subroutine go into the @_ array. The @numbers array is empty until you load it up in the foreach loop. Having 5 and 6 as arguments does not automatically put those items into @numbers, nor does @numbers copy anything into @_. Also, I understand that you may just be testing out persistent variables in 5.10, but this program is confusing. Consider what happens if you call running sum a second time (say as running_sum( 2, 7 );) If I add that call, here's my output: telemachus ~ $ perl sum The sum of (5 6) is 11 The sum of (5 6 2 7) is 31 That appears to say that perl has added 5, 6, 2, and 7 up to 31. What actually happened was that you added 5, 6, 2 and 7 (20) to 11 (the sum from the previous call to running_sum - which was saved). To put this another way around: maybe you want to keep a running sum, but the print statement in the subroutine is very confusing. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Updating Perl 5.8.8 to 5.10 under MacOSX and Eclipse EPIC
On Sun Jan 18 2009 @ 4:35, Steven Sankaran wrote: > Hello, > So, I was going through a tutorial and I realized that my Eclipse > install is using an older version of Perl that does not recognize the > "say" command. I have attempted updating Perl to 5.10 using the > ActivePerl-5.10.pkg ,however, as far as I can tell, that doesn't seem > to be working. I am currently running the latest version of Mac OSX, > which is currently running 5.8.8. How do I update this to 5.10, so > that I may use the "say" command? I run the installer, but it does not > seem to be helping. Is there something I am missing? > > Any help would be greatly appreciated, > Thank you. > > -Steven Your default perl lives at /usr/bin/perl and as I recall, ActiveState's package puts the new one in /opt. So the problem is probably that Eclipse is not "seeing" the newly installed 5.10. I don't know how to set such a preference in Eclipse, but this may help point you in the right direction. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Newbie question about variables, arrays and where they all go
From: Telemachus Date: Sun, 18 Jan 2009 20:17:27 -0500 To: beginners@perl.org Subject: Re: Newbie question about variables, arrays and where they all go On Sun Jan 18 2009 @ 7:54, Telemachus wrote: > The arguments to a subroutine go into the @_ array. The @numbers array is > empty until you load it up in the foreach loop. Edit: I should have said that the @numbers array is empty before the *first* run. Since it's persistent, after that it already contains all the items from previous calls. So on a second call, it already has 5 and 6. (I should also consider spelling 'understand' with a d.) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Updating Perl 5.8.8 to 5.10 under MacOSX and Eclipse EPIC
On Sun Jan 18 2009 @ 6:31, Steven Sankaran wrote: > Hm. I have spent the last hour or so attempting to get this to work, > but I cannot seem to get Perl to update. I have located the 5.10 > directory under /usr/local/ActiveState-5.10 but I cannot get Eclipse > to recognize it. I even tried Eclipse and EasyEclipse. Does anyone > have any other IDE suggestions for Mac OSX? Perhaps something a little > more user friendly. I use MacVim on OS X (http://code.google.com/p/macvim/), but that's essentially just a gui version of vim, not a full IDE. The IDE I hear the most about for Mac is TextMate (http://macromates.com/), but I've never tried it. As for Perl, you *did* install an updated version of it. By default, a newer version won't (and probably shouldn't) simply overwrite your system's version. The system may depend on various things being the way they are with the Perl they ship. So, only Mac should update the Perl in /usr/bin (don't hold your breath). However, there's nothing to stop you from installing a newer version somewhere else, as you did, and using that version. Probably the first thing you need to do now is update your $PATH. If you open the .profile file in your user home directory (/Users/your-name/.profile), you want to add a line like this to it: export PATH=/usr/local/ActiveState-5.10/bin:$PATH That simply prepends the new ActiveState directory to your already existing path. When a shell looks for a perl binary, it should now find the new one first. After you do the edit, source the new path and test it with the command "which perl". Here's how to source it. Type this in a shell: . .profile This may even help the Eclipse problem, though I doubt it. I would check its documentation and see what it says about changing your $PATH or multiple insallations of one interpreter. HTH, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Using / of unix and \ of windows for copying files
On Mon Jan 19 2009 @ 2:13, Sarsamkar, Paryushan wrote: > Hi All, > How can I work with / and \ here? My suggestion would be to use File::Spec rather than hardcode the \ or / as a path separator. See perldoc File::Spec for more information, but in a nutshell, it's a core module built to "portably perform operations on file names." The 'catfile' method should do what you need. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Newbie question about variables, arrays and where they all go
On Mon Jan 19 2009 @ 4:21, dolphin_sonar wrote: > Again, you answered my question. You should be teaching Perl as your > responses are very clear and that's not easy for people to do...give > clear, concise responses. Actually, I had a big goof in my response. The program and the print statement are fine as you had them, and *I* got myself turned around. When I typed up your program, I was thinking of other ways I might do it, and I produced this: sub running_sum { state $sum = 0; state @numbers; push @numbers, @_; $sum += $_ foreach @numbers; ## WRONG - should be foreach @_ say "The sum of (@numbers) is $sum"; } I thought it would be easier to push the whole @_ array into @numbers at once and add everything into $sum in a one-liner as well. But I did it wrong. The problem was that I added the entire @numbers array to $sum, but from from call to call, I only want to add the new items (the ones in the @_ array). That's what I get for trying to answer a question and rewrite the example all at the same time. As for 'say' it's a new feature in 5.10 (like the state variables) which allows you to print without explicitly asking for the "\n" - it looks like it's officially introduced in Learning Perl 5e on page 90. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perlscript
On Fri Jan 30 2009 @ 5:34, Octavian Rasnita wrote: > Hello, > > Does anyone have some recommendations for some tutorials/documentation > for using perlscript as a client-side language in browsers? > > Thank you. > > Octavian Never knew that there was such an animal. A quick Google search offers this: http://www.cpan.org/authors/id/M/MS/MSERGEANT/PSIntro.html It hasn't been updated since June of 1998, which is not a good sign. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: local perl documantaion
On Wed Feb 04 2009 @ 5:49, Dermot wrote: > Hi, > > I have until recently used a widows box and Activestate's perl. I now > use a *nix box. Something I am missing a lot is the html documentation > tree that Activestate builds when it's installed and keeps up to date > with it ppm. > > Is there a way to achieve something similar on a *nix box or do I have > to hand-roll a find/pod2html script? > > TIA, > Dp. I'm not familiar with the Activestate version, so I'm not sure how close it is, but check out Pod::Webserver at the CPAN. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ending a character to each line
On Thu Feb 05 2009 @ 11:17, stuforman wrote: > i want to use perl to end each line with a '~'. i would really > appreciate any syntax that would help me do this... > > thanks in advance Here's one quick version. This will work and ignore lines without any text or spaces: perl -ple '$_ = "$_~" unless m/^$/' filename Try it and if the output is good, you can save to a new file with redirection or by adding -i.bak (to edit in place and save backups to filename.bak). HTH, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to speed up two arrays compare.
On Wed Feb 11 2009 @ 4:04, kevin liu wrote: > Hi everybody: > > I have two arrays(@nwarray0 and @nwarray1) in my program and i want > to make sure that all the elements in @nwarray0 could be found in @nwarray1. Check 'perldoc -q array' - two or three of the FAQ answers touch on different ways to compare arrays, test them for equality, etc. As Raymond said, the basic answer seems to be "Use a hash," but there are lots of good examples to play with. HTH, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl deprecated functions and alike
On Sun Feb 15 2009 @ 9:45, Octavian Râsnita wrote: > From: "John W. Krahn" >> Kevin wrote: >>> Could someone please direct me to some web pages where I can go >>> through all deprecated perl functions and/or ways of writing perl >>> script? It is not easy for me to figure out whether an on-line >>> example is deprecated or not. I once saw: >>> >>> @files = <$path_to_directory> >>> >>> on the web and found it worked perfectly, then kept using this way of >>> writing my perl script. But I was told yesterday such a script is >>> deprecated now. >> >> AFAIK that is not deprecated. > > Can you explain how it works? > > I have tried the script below, and of course it doesn't print anything: > > use strict; > > my $path_to_directory = '/'; > > my @files = <$path_to_directory>; > > foreach my $file(@files) { > print "$file\n"; > } > > Thanks. > > Octavian Yup, I'm confused as well. At first, I thought it was the alternative way to write glob( $path_to_directory ), but not exactly. According to perldoc perlop, @files = <$path_to_directory > (note the extra space) will work as a glob, but otherwise, the interpreter thinks that you are trying to run readline on an unopened filehandle. Running a short test script with 'diagnostics' enabled, I get this: readline() on unopened filehandle $path at files line 7 (#1) (W unopened) An I/O operation was attempted on a filehandle that was never initialized. You need to do an open(), a sysopen(), or a socket() call, or call a constructor from the FileHandle package. (Are you trying to call readline() on dirhandle $path?) So, I would also be curious to know what that construction is supposed to do. Thanks, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Add Line break when first of a line changes
On Sun Feb 15 2009 @ 7:25, Jack Butchie wrote: > I have a txt file of products that I would like to be able to insert a > blank line whenever the name of the product changes, to make it easier to > read. I found this srcipt hunting about but I don't know how to apply it > to the text file. I've tried all kinds of different things but just don't > get it. Do you already have Perl installed on your computer? If so, you can run it as follows. Save the Perl script with whatever name you like - say, new_liner. Then enter this into a terminal: perl new_liner filename Instead of 'filename', enter the name of the file you want to work on. The two files should be in the same directory for this to work. Otherwise, you will need to enter the full path of the file, perl new_liner /path/to/filename You should get output like this: telemachus ~ $ perl new_liner feed LAWN SEED 34.00RED LAWN SEED136.00BLUE LAWN SEED136.00BLUE LAWN SEED136.00BLUE LAWN SEED237.00PINK Assuming that the output comes out as you want it, you can save it to a new file with redirection: perl new_liner feed_file > new_feed_file In a nutshell, the script is taking a single filename as an argument, opening the file and then checking line n for equality with n-1. It will work with exactly the setup you describe, but it's not a very maintainable situation (a single extra space or typo will bork the equality test, there's no way to deal with too many or two few filenames entered on the command line, etc.). As a more general rule, I would have to recommend *not* running scripts you don't understand that you find floating around on the interwebs. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Add Line break when first of a line changes
On Sun Feb 15 2009 @ 8:56, Jack Butchie wrote: > I did some fiddling with the list. I noticed if the second or third or > whatever column wasn't exactly the same as the previous, even though the > tex in the first field was the same, line was being added. I then tested > with only the first field in the list and it worked perfectly. The script > seems not to like anything different in other columns/fields. > > LAWN > LAWN > LAWN > PORCHES > WARTHOGS Right, as I said (and Gunnar made clearer), this is *not* testing product names for equality. It's testing the entire lines for equality. Which field do you actually want to test? Now that I look at your initial email, I'm guessing that what you actually want to test is "LAWN SEED" against "LAWN SEED1" - which makes things a bit more complicated. Your file doesn't have a consistent field separator (sometimes a space is part of a product name, sometimes not). A solution that works for "LAWN SEED" and "LAWN SEED1" won't be identical to one for "LAWN SEED1" compared to "MULCH". So, what does the file really look like? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Add Line break when first of a line changes
On Sun Feb 15 2009 @ 9:48, Jack Butchie wrote: > I used a tab, then a pipe, both produced the same results. > > LAWNS|123|GOOD > > LAWNS|12|GOOD The results are the same because the test is for the whole line. If you only want to test one field, you need a different script. For example, this will test the first field (only) of each line: #!/usr/bin/perl -w my $file = shift @ARGV; open IN, $file or die "Couldn't open $file: $!"; my $before; while (my $line = ) { my $now = (split /\|/, $line)[0]; if ($before and $before ne $now) { print "\n"; } print $line; $before = $now; } close IN; On the other hand, this is getting more and more hacked together, as you can see. The big problem remains that you are going to have a script that you can't maintain because you don't know how it works. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Bundle-Expect
On Fri Feb 20 2009 @ 3:02, ramesh.marimu...@wipro.com wrote: > > Thanks Thomas. Actually when is give "use Expect;", the error I get is "Can't > locate Expect.pm in @INC ...". Is there anything that I'm missing or should I > check something? > > -ramesh As a start, you can run this command to see what @INC is: perl -e '$"="\n"; print "@INC\n"' If you have multiple versions of Perl installed, make sure that the version you call in your script is the same as the one you use at the command line. (You can use 'which perl' at the command line to check that.) That is, if you call #!/usr/bin/perl in your script, make sure you aren't using /usr/local/bin/perl at the command line. Once you know what @INC is for your installation, you need to find where Expect got installed. Some combination of 'find' and 'locate' should help you out there. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
On Fri Feb 20 2009 @ 10:28, Dermot wrote: > 2009/2/19 mritorto : > > guys > > > > more questions > > > > > > isn't built in. I am using active state perl > > > > > > can u recommend any good perl books the ones I have aren't make for > > beginers like perl cookbook or perl in a nutshell > > I'd say start with this. > Learning Perl (4th edition) ISBN 0-596-10105-8 I second the recommendation, but there's a 5th edition, so go for that one instead. (It's updated for Perl 5.10.) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reading 2 array lists
On Fri Feb 20 2009 @ 1:29, mrito...@gmail.com wrote: > I have that one > > I need one for perl dummies like me If you want an alternative, take a look at Beginning Perl by Simon Cozens: http://www.perl.org/books/beginning-perl/ It's written for Perl 5.6 (I think), but the core of the syntax should be fine. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: flattening @AoA
On Mon Feb 23 2009 @ 6:27, r...@goto10.org wrote: > problem with below > > @linearray prints - but just prints an array of array references (i think > thats > what it is anyway!) i tried to flatten it to @array but i dont really know > what > i am doing. > i need to have all the data in @linearray arranged so i can do pattern > matching > on a line by line basis. each line being one of the permutations of > @phrasegroup. > > any clues? > > many thanks > > rob > > my @phraseA = ("%1\$s'16-> ", "%2\$s16-> ", "%3\$s16-> "); > my @phraseB = ("%4\$s'''16-. ", "%5\$s16-. ", "%6\$s16-. " ); > my @phraseC = ("%7\$s''16-- ", "%8\$s16-- ", "%9\$s16-- "); > my @phraseD = ("%10\$s''16-+ ", "%11\$s16-+ ", "%12\$s16-+ "); > my @phraseE = ("%13\$s'''16-_ ", "%14\$s16-_ ", "%15\$s16-_ ", "r16"); > > my @phrasegroup = ([ @phraseA ], [ @phraseB ], [ @phraseC ], [ @phraseD ], [ > @phraseE ]); > > > my @linearray = join("\n\n", map { join " ", @$_ } > permute(@phrasegroup)),"\n"; > > my @array = map { @$_ } @linearray; > > print @linearray; > > print @array; It sounds as though you are trying to treat an array like a file. That is, you want to go through it "line by line", and you're trying to create a new array (@linearray) by joining the flattened results of the permute subroutine with newlines. But the join function takes a list and produces a string (one thing). You seem to be using it backwards - or I'm very confused by your code. I don't know what's in the permute subroutine, but the problem definitely looks to be in this line: my @linearray = join...etc. Take a look at perldoc -f join and maybe try to explain what you're trying to do in that line. Hope this helps. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Is there function to separate print associative array
On Sun Mar 01 2009 @ 1:04, Octavian Râsnita wrote: > From: "prasath_linux" >> Hi, >> >> Is there any possible function to print the associative array. We >> have print_r() function in PHP to display the associative array. >> Likwise is there any function in perl to print associative array. >> >> Thanks in advance. >> > > > You can use: > > use Data::Dump qw(pp); > > my %hash = (a => 1, b => 2); > > print pp(\%hash); > > Octavian Just a note - Data::Dump is not a core module, so the first step would be to install it and then try Octavian's program. You could also use the less pretty, but very functional, Data::Dumper (which is a core module, so no extra installation is required): use Data::Dumper; my %hash = (a => 1, b => 2); print Dumper \%hash; Even more generally, if you want to work on everything in a hash, you can iterate over its keys or key/value pairs using the 'keys' or 'each' keyword: foreach my $key (keys %hash) { print "$key => $hash{$key}\n"; } while ( my ($key, $value) = each %hash ) { print "$key => $value\n"; } Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: word similarity measure
On Fri Feb 27 2009 @ 8:24, Susan wrote: > If my data looks like this: > > word 1: 100101 101102102 102106106 > word 2: 101104 106110113 129131148 > word 3: 101153 175180381 > word 4: 106110 113122131 137142148 > word 5: 120165 169 > > where word 1,2,3,4,5 represent different words, numbers represent > different attributes of words. > > How can I calculate similarity between words? Like John and Chas, I'm not entirely sure what you mean by similarity. My guess is that you want to see what attributes the various words share. So, for example, word 1 and word 2 both have attributes 101 and 106. However, I'm not sure why a word can have the same attribute twice or even more. That is, I don't know if that means anything (word 1, for example, has 101 twice, 102 three times and 106 twice - whatever that means). Still, it's a snow day for me here, and Chas's version made me think more about this, so here's a stab at it. This compares words two at a time, and I wonder if you actually wanted to compare them against each other all at once. If so, it might be better to turn your data inside out - make the attributes the keys and create lists of words that have that attribute. Also, I didn't clean up the "results" print out, so right now you get each result twice (word 1 and word 5 share...and later word 5 and word 1 share...). #!/usr/bin/env perl use strict; use warnings; my %word_attributes; while () { chomp; $_ =~ s/^(.*)://; next unless $1; my $word = $1; $_ =~ s/^\s+//; $word_attributes{$word} = [ split /\s+/, $_ ]; } foreach my $key (sort keys %word_attributes) { my @outer = @{ $word_attributes{$key} }; @outer= remove_dups(@outer); foreach my $key2 (sort keys %word_attributes) { next if $key2 eq $key; my @inner = @{ $word_attributes{$key2} }; @inner= remove_dups(@inner); my (@intersection, %count); foreach my $attribute (@outer, @inner) { $count{$attribute}++ } foreach my $attribute (keys %count) { if ($count{$attribute} > 1) { push @intersection, $attribute; } } print "$key and $key2 share "; if (@intersection) { @intersection = sort { $a <=> $b } @intersection; print "these attributes: @intersection\n"; } else { print "nada\n"; } } print "\n"; } sub remove_dups { my @attributes = @_; my %seen; @attributes = grep { !$seen{$_}++ } @attributes; } __DATA__ word 1: 100101 101102102 102106106 word 2: 101104 106110113 129131148 word 3: 101153 175180381 word 4: 106110 113122131 137142148 word 5: 120165 169 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Accepting default value for user input
On Mon Mar 02 2009 @ 7:54, Sarsamkar, Paryushan wrote: > Ohh ... sorry ... after rethinking over it ... I think it converts the > $normal to lower case before comparison Right, which is a standard and smart thing to do since you can't count on your users to correctly type 'y-e-s'. Damn users. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Printing directory sizes
On Tue Mar 03 2009 @ 10:21, Lauri Nikkinen wrote: > Ok, thanks. Now I notice that I did not understand correctly what this > script does. I was trying to print sizes of all directories in the directory > tree. But anyway, I appreciate your kind help! The line find( sub { #code here}, $dir ) simply runs the code in the subroutine on the directory you specify with the $dir variable. Now let's look at what's in your subroutine: > > > find( sub { -f and ( $size += -s _ ) }, $dir ); That line tests if each item in $dir is a *file* (-f). If it is, then the code continues and adds the size in bytes of that same item to the $size variable. I don't mean to go on and on about this, but the code doesn't match what you're describing you want to do above: you aren't testing for *directories* only for files, and you aren't asking to print out any results. So, as Chas said, your first problem is that you aren't printing out any output. Your second problem is that you aren't gathering total size by directories. Your simply gathering the sizes of all the files in $dir and any subdirectory starting from $dir. The way that File::Find works is a little unusual, and for me at least was initially confusing. You might want to read through this article, which includes successively more complex examples: http://www.stonehenge.com/merlyn/LinuxMag/col45.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Printing directory sizes
On Tue Mar 03 2009 @ 4:03, Telemachus wrote: > > > > find( sub { -f and ( $size += -s _ ) }, $dir ); > > That line tests if each item in $dir is a *file* (-f). Sorry: hit send too quickly. What I meant to say there is that the subroutine tests for files - starting from whatever directory you specify in $dir and drilling recursively down and down. Anything it finds that is a file, it gets the size of and adds that number to $size. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Parsing file line by line.
On Tue Mar 10 2009 @ 4:13, Meghanand Acharekar wrote: > Hi, > > Need some help > How can I parse a file line by line using perl. > > I want to parse a test file having following data format > > *File : user_stats.txt* > 20GB Larry > 14.5MB Bob > 3MBJohn > > so that I can send this data to a MySQL database table. > Can I use while loop (any other loop control) for this ? > Yes, you can use a while loop to work on a file line by line #!/usr/bin/env perl use strict; use warnings; open my $data_file, '<', 'user_stats.txt' or die "Can't open 'user_stats.txt' for reading: $!"; while (my $line = <$data_file>) { next if $line =~ m/^\*File/; my @fields = split /\s+/, $line; print "@fields\n"; } You would need to adjust for the proper path to user_stats.txt, and the code inside the while loop is just for show. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed in understanding some lines of code.
On Thu Mar 19 2009 @ 10:41, Chas. Owens wrote: > On Thu, Mar 19, 2009 at 06:11, Raheel Hassan wrote: > > Can anybody explains this piece of code, i have difficulties in > > understanding it, You're much nicer than the folks over at Linux Questions. http://tinyurl.com/dhncl4 Then again, he did format the code at least a bit for the email. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: quick regex question
On Wed Mar 25 2009 @ 12:19, Rodrick Brown wrote: > On Wed, Mar 25, 2009 at 12:00 PM, Rick Bragg wrote: > > I need a quick regex to strip out the following: > > > > example: > > change "remove-all-this (Keep This)" into just "Keep This" > > > > $s =~ s/.*\((.*)\)/$1/; > > > something like: > > s/ beginning of line up to and including the first ( //g > > s/ starting from and including first ) to end of line //g But if there's anything after the 'Keep this', you have problems with this version: use strict; use warnings; my $string = 'remove-all-this (Keep this) remove this too'; $string =~ s/.*\(//; $string =~ s/\).*//; print "$string\n"; my $string2 = 'remove-all-this (Keep this) remove this too'; $string2 =~ s/.*\((.*)\)/$1/; print "$1\n" if $1; print "$string2\n"; For $string2, you end up with "Keep this remove this too" since you replace the 'Keep this' back into the rest of the string. (That is, you substitute 'remove-all-this (Keep this)' with 'Keep this'. So if you have anything after the closing paren, you have a problem. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: quick regex question
On Wed Mar 25 2009 @ 3:10, Chas. Owens wrote: > On Wed, Mar 25, 2009 at 13:21, Telemachus wrote: > snip > > my $string2 = 'remove-all-this (Keep this) remove this too'; > > > > $string2 =~ s/.*\((.*)\)/$1/; > snip > > If $string2 may contain more than one pair of parentheses, you will want to > say > > $string2 =~ s/.*\((.*?)\)/$1/; > > or > > $string2 =~ s/.*\(([^)]*)\)/$1/; Either I misunderstood the OP's request, or these two are still no good. They don't trim away what follows the closing parenthesis. As I understood the OP, he wanted to remove everything except the info inside of the parens. That is, what he wants left is only 'Keep this'. I think that this would work fine: my $string = 'remove-all-this (Keep this) remove this too'; $string =~ s/.*\((.*?)\).*/$1/; But as you say, if there are multiple instances or nested parens, then this is all the wrong way to go. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Pattern matching question
On Tue Mar 31 2009 @ 3:32, Richard Hobson wrote: > It works, but is there a way of combining these lines: > > my $piece = $ref->[$_]; > $piece =~ /.*(..$)/; > > It feels like this could be done in one step. Is this correct? I'm > finding that I'm doing alright in Perl, but I sense the Perl urge to do > things in as few a number of steps as possible. You can capture and assign in a list context. (A scalar context won't work, since it only returns a true or false value then to tell you if you captured anything at all). This should work: my ($piece) = ($ref->[$_] = ~ /.*(..$)/); # Check here for $piece? Ie, check if anything was captured? # Later print $pieces{$piece}; See the 'Extracting matches' section of perldoc perlretut. However, I would recommend that you _avoid_ the urge to do things in as few steps as possible if it's not clear to you what the short version is doing. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Printing directory sizes
On Tue Mar 31 2009 @ 11:08, Octavian Râşniţă wrote: > Do you know if du has a parameter that lets us see the size of the files > from chosen directories? > > I've seen that it shows the disk usage only. >From man du: -a, --all write counts for all files, not just directories (The flag may vary by version or implementation. Mine is GNU coreutils 7.1) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl script to check whether software is installed
On Mon Apr 06 2009 @ 2:44, Irfan Sayed wrote: > please adivce / help > > Regards > Irfan Please don't reply to your own mail as a way of nudging people to reply. It's more likely to annoy than to get you an answer. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: "Programming Perl" vs perldoc
On Wed Apr 08 2009 @ 1:08, Richard Hobson wrote: > But, what's the advantage of "Programming Perl" when we have "perldoc"? > What does the book give me that perldoc does not? One thing that nobody has mentioned is that Programming Perl hasn't been updated since Perl 5.6. There have been two major releases since that, and we're now at 5.10. Your system probably has some version of 5.8 if it's relatively recent. In many ways, the big picture is probably still the same, and many of the docs probably haven't been rewritten either, but the docs for your installation should be closer to the Perl you're actually working with. I second the recommendation that you look through the tutorials in perldoc. Many are excellent and perfect for intermediate development. I especially recommend these: perldoc perlreftut (How to make and use references) perldoc perllol (Arrays of arrays, more complex data structure) perldoc perldsc (All kinds of complex data structures) perldoc perltoot (Introduction to OO programming in Perl, not to OO itself) perldoc perlretut (Regular expression tutorial) perldoc perlopentut (How to open things in Perl - it's much more fun than it sounds) Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: "Programming Perl" vs perldoc
One other thing: http://perldoc.perl.org/ is an excellent way to read the docs online (searchable too), and it provides pdf versions of almost everything. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: LWP
On Wed Apr 08 2009 @ 3:22, ANJAN PURKAYASTHA wrote: > I have a file stored at a location: http://parent_dir/file > Which among gazillion LWP options can I use to download and store the file > on my machine? > TIA > Anjan If you just want to grab the file, you can use LWP::Simple to grab it: use LWP::Simple; my $url = 'http://parent_dir/file'; my $local = '/path/to/local/file'; my $file = getstore($url, $local); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: LWP
On Wed Apr 08 2009 @ 10:29, Gunnar Hjalmarsson wrote: > Telemachus wrote: >> On Wed Apr 08 2009 @ 3:22, ANJAN PURKAYASTHA wrote: >>> I have a file stored at a location: http://parent_dir/file >>> Which among gazillion LWP options can I use to download and store the file >>> on my machine? >> >> If you just want to grab the file, you can use LWP::Simple to grab it: >> >> use LWP::Simple; >> >> my $url = 'http://parent_dir/file'; >> my $local = '/path/to/local/file'; >> my $file = getstore($url, $local); > > getstore() returns the HTTP status code, so 'file' is not the most > appropriate name of a variable to which the return value is assigned. Gah: you're absolutely right. The last line is the coding equivalent of a mixed metaphor: half of my brain was thinking this: my $file = get($url); print $file; The other half of my brain thought: getstore($url, $local); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Push to AoA
On Wed May 13 2009 @ 9:22, Steve Bertrand wrote: > Jim Gibson wrote: > > The first argument of push should be an array, not a scalar (even if that > > scalar is a reference to an array). > > > > push( @{$graph_data->[0]}, $x_axis ); > > I'll have to do a bit of reading, because I can't remember why the > braces are important here. All I know is that it works ;) The general rule for using a reference is write what you would have written, but put the reference inside of brackets. So, for example, Regular Reference @array@{$array_ref} %hash %{$hash_ref} If the reference itself is a simple scalar variable, then the brackets aren't required. So both of the cases above could be written more simply as @$array_ref and %$hash_ref. However, if the reference is not a simple scalar variable, then the brackets are required, not optional. In your case, the variable $graph_data->[0] is itself a reference, so the brackets aren't optional. The other thing that may be confusing you is that if you are referring to a single item from a hash or array, you can use the arrow syntax rather than the bracket syntax. So, deciding what you need is a two stage process: (1) Am I trying to use an entire hash or array reference? (a) Yes: wrap the reference inside of { } and put the proper sigil on it. Eg, @{$array_ref} %{$hash_ref} (b) Yes and the reference itself is a simple scalar: ok, then the braces are optional. Eg, @$array_ref, %hash_ref (2) Am I trying to use a scalar from an array or hash? (a) Yes: Instead of ${$ref} use $ref-> Some people say always use the brackets for whole arrays or hashes (ie, 1a rather than 1b) simply because fewer choices are fewer things to remember or mess up. Others hate the look of @{$array_ref} so much that they say use 1b whenever possible. This may help: http://www.perlmonks.org/?node_id=69927 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: prob w/anonymous array
On Wed May 20 2009 @ 1:50, pa...@compugenic.com wrote: > I have the following data structure defined: > > my @clients = ( > { > name=> 'joe', > count => [ qw( one two three ) ] > } > ); > > Then I try running the following routine: > > for my $client (@clients) { > for my $i ($client->{count}) { > print "$i\n"; > } > } > > I expect it to print the following: > one > two > three > > But instead, it prints out the following: > ARRAY(0x8b4b880) > > If I change it to: > for my $i (@$client->{count}) { > print "$i\n"; > } > > I get the error: > Not an ARRAY reference at ./test_data_structure.pl line 12. > > > My question is what am I doing wrong? How to I loop over each element > in my anonymous array to process it? I've read the data structure > tutorials and tried different things, but just can't seem to get this to > work. The problem is that you can only use @$array_ref if array_ref is a simple scalar. What you want to put there is itself a reference - client->{count} so you need brackets to refer to the entire array. This should do what you want: for my $client (@clients) { for my $i (@{$client->{count}}) { print "$i\n"; } } You might also take a look at this: http://www.perlmonks.org/?node_id=69927 I hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: readdir() question
On Mon May 25 2009 @ 4:34, sanket vaidya wrote: > Hi all, > > > > Kindly look at the code below: > > > > use warnings; > > use strict; > > opendir(DIR, "D:\\test") || die "can't opendir: $!"; > > my @dots = readdir(DIR); > > print map{"$_.\n"}...@dots; > > > > .. > > ... > > Test1 > > Test2 > > Test3 > > > > Where Test1, Test2, Test3 are files within test directory. > > > > Apart from that I also got dots (2 in 1st line & 3 in 2nd line). I know that > '..' stands for parent directory what does '...' mean? Your real output must have looked more like this: .. ... Test1. Test2. Test3. You put a period ('.') near the end of your call to print, so instead of seeing '.' and '..' (current and parent directory), you're seeing '..' and '...' (current and parent directory plus the period). > In perldoc of readdir() I am unable to follow below line. Can anyone explain > me the below line with example? > > > > 'If you're planning to filetest the return values out of a readdir > <http://perldoc.perl.org/functions/readdir.html> , you'd better prepend the > directory in question. Otherwise, because we didn't chdir > <http://perldoc.perl.org/functions/chdir.html> there, it would have been > testing the wrong file.' Consider this: use strict; use warnings; opendir(my $dh, '/home/telemachus/practice') || die "can't opendir: $!"; my @contents = readdir($dh); my @files = grep { -f "/home/telemachus/practice/$_" } @contents; my @noprepend = grep { -f $_ } @contents; print "With prepending:\n"; print "\t$_\n" for @files; print "Without prepending:\n"; print "\t$_\n" for @noprepend; The first grep prepends (adds at the beginning) the path to each file. If you don't do that, you're testing for files in the directory where you call the script (or wherever the script happens to be, if you've changed directory at some point). Change the path to something reasonable for your system (in both the call to opendir and the my @files line) and compare the output you get for the two different uses of grep. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: List of perl functions that work on LINUX & not in Windows
On Fri May 29 2009 @ 10:00, sanket vaidya wrote: > Kindly provide a list of perl functions that work on LINUX but not on > windows. Also provide the list of functions that behave differently on > Windows & LINUX. This not project requirement. I just want to explore the > functions on LINUX. So far I have been using ActiveState Perl on Windows. I'm not sure if there is such a list. But this may help to give you an idea of Perl on different systems: http://perldoc.perl.org/index-platforms.html I hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: file handle in perl
On Wed Jun 17 2009 @ 3:42, Ajay Kumar wrote: > Hi Irfan > You can do all four task like below > > 1: open FILE ,">filename.txt" or die$!; > 2: my @lines= > 3: do changes through sed > Like sed -e 's/original pattern/new pattern/p' filename > 4:if you did changes it automatically get saved > 5: close(FILE); I hear that Perl can do some of this stuff too. For safety's sake, let's think of it as two tasks. First, read in data from file1, change the data in whatever ways we want, then print out the new version to file2. Nothing happens to file1 until that's finished. Second, we rename file1 to file1.bak (to keep a backup) and we rename file2 to file1. It all happens so fast that it feels as if we edited in place, but we didn't. #!/usr/bin/perl use warnings; use strict; # Let's use lexical filehandles, not barewords # And while we're at it, let's use the three-argument form of open # See perldoc -f open open my $in, '<', 'filename.txt' or die "Can't open [filename.txt] for reading: $!"; open my $out, '>', 'newversion.txt' or die "Can't create [newversion.txt] for writing: $!"; # Run through the file line by line for processing while (my $line = <$in>) { # code to make changes here print $out $line; # No comma! See perldoc -f print } # Close tidily or crash and burn close $in or die "Can't close [filename.txt]: $!"; close $out or die "Can't close [newversion.txt]: $!"; # The old switcheroo rename 'filename.txt', 'filename.txt.bak' or die "Can't rename [filename.txt]: $!"; rename 'newversion.txt', 'filename.txt' or die "Can't rename [newversion.txt] to [filename.txt]: $!"; This is a pretty simple thing to do in Perl, and there are ways to use more magic to make it briefer. In particular, see perldoc perlrun for how to use -i, -n, -p, -l and -e (not all at once, necessarily) to make this a simple one-liner in many cases. That said, there's nothing wrong with knowing how to do it yourself for more complex cases where a one-liner wouldn't cut it. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Replace System("Dir") call Help
On Sun Jun 21 2009 @ 7:40, AndrewMcHorney wrote: > Hello > > I have written a perl script and I am in the debugging and imroving the > code. The first improvement is want to make is to replace the > system("Dir c:/s") call because it is not portable. So I was told to use > the File package. I think you want File::Find, not just File. You can start by looking at perldoc File::Find, but for many people, that module isn't intuitive at first. I would recommend that you also read this article: http://www.stonehenge.com/merlyn/LinuxMag/col45.html In terms of replacing system("Dir c:/s"), you should also look at these functions: perldoc -f opendir perldoc -f readdir But in a case like this, you probably want to leverage File::Find rather than writing all the code yourself. Hope this helps. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ref() or ! ref()
On Mon Jun 22 2009 @ 11:10, Steve Bertrand wrote: > I've got a relatively decent understanding of how references work in > Perl (syntax-wise, especially when/how to de-ref), but I'd now like to > ask when to use them. > > Obviously memory allocation isn't an issue anymore, so when exactly > should refs be used, and in what circumstances shouldn't they be used? I'm not quite sure what you mean by "memory allocation isn't an issue anymore." Do you mean "With modern hardware, who cares about memory saving?" If so, I don't know that I would go that far. Premature optimization may be evil, but copying huge arrays and hashes just for fun seems silly, too. So, I do use references when passing arrays or hashes to functions or returning them from functions. More generally, references are essential for complex data structures. My favorite brief introduction to references comes at them from that angle: perldoc perlreftut You might also take a look at two other tutorials in perldoc: perldoc perllol perldoc perldsc Enjoy, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Getting started
On Wed Jun 24 2009 @ 2:16, Daryl Styrk wrote: > I've purchased "Learning Perl" to finally give picking up perl a fair > shot. However in the beginning of the book it suggest that I should have > an understanding of basic programming concepts such as variables, loops, > subroutines, and arrays... Well, I don't. I was hoping that this book > would somewhat cover it all. I have some experience with bash, not much.. > More less copying/pasting scripts and perhaps a slight edit here and > there. Nothing that has reveled itself as one of the above functions. Learning Perl occasionally moves quickly, but for the most part I actually think it should work fine for a new programmer. If you find yourself wanting a more beginner-level treatment of the same topics, you might check out Beginning Perl. The first edition of that is available freely online (and legally, too): http://www.perl.org/books/beginning-perl/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File::Find with chmod trouble debugging
On Mon Jul 06 2009 @ 7:00, Harry Putnam wrote: > Can anyone tell me how printing of $mode = 0755 turns into 493? Yup: what's in $mode is an octal number. Its decimal equivalent is 493. What you really want to print out is the string '0755', but the string and the octal number are not the same thing. The good news is that your problem is a lot less bad than the more common one: chmod (755, foobar). (755 is 1363 in octal, an odd choice for permissions.) Try using printf and %o, which should give you 755 for $mode. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: File::Find with chmod trouble debugging
On Mon Jul 06 2009 @ 3:31, Harry Putnam wrote: > Thanks to all ... > Now I'm curious about something else: > > Is the mode in a stat(file) readout something still different > than octal or decimal? As John answered, there's more there than just the permissions. If you check perldoc -f stat, there's a recipe for how to get what most people usually want out of that field: Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a "%o" if you want to see the real permissions. $mode = (stat($filename))[2]; printf "Permissions are %04o\n", $mode & 0; Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Understanding recursion
On Fri Jul 10 2009 @ 9:26, Dermot wrote: > The algorithm works perfectly but my understanding of it's workings is amiss. > > When I look at this I see $E initialised and then concatenate with the > the modulus of > 37 % 2 =1 > 18 % 2 = 0 > 9 % 2 = 1 > 4 % 2 = 0 > 2 % 2 = 0 > > That by my reckoning is 10100. Almost the reverse of the answer but I > am obviously wrong and I can't see how the final expressions: > > my $E = binary($k); > return $E . $b; > > work to give the answer. It helps for me to walk through it visually, indenting once each time the script needs to call the binary sub-routine. Notice that it keeps going down and inward, until it "bottoms out" on the base case. At that point, the answers ripple back up to fit into the calls to binary($E) that were left hanging (because in those cases $E wasn't 1 or 0). Maybe this will help you as well. Does 37 == 0 || 1? No; continue... $k = 18; $b = 1; $E = binary(18) -> go do that... Does 18 == 0 || 1? No; continue... $k = 9; $b = 0; $E = binary(9) -> go do that... Does 9 == 0 || 1? No; continue... $k = 4; $b = 1; $E = binary(4) -> go do that... Does 4 == 0 || 1? No; continue... $k = 2; $b = 0; $E = binary(2) -> go do that... Does 2 == 0 || 1? No; continue... $k = 1; $b = 0; $E = binary(1) -> go do that... Does 1 == 0 || 1? Yes; return 1 $E = 1; return 1 . 0 $E = 10; return 10 . 0 $E = 100; return 100 . 1 $E = 1001; return 1001 . 0 $E = 10010; return 10010 . 1 Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: bug in perl
On Fri Jul 17 2009 @ 3:18, Octavian Rasnita wrote: > From: "Shawn H. Corey" >> Octavian Rasnita wrote: >>> Well, in PHP that calculation is made well, so I think there is a bug >>> in perl. >>> >> >> No, it's not. PHP rounds off the number before printing. In Perl: >> >> printf "%.2f", $x; >> >> or >> >> $x = sprintf "%.2f", $x; >> > > Ok, thank you all for your help. I think that this is the politest blow-off I've ever seen. Well done. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: two questions
On Thu Aug 06 2009 @ 2:29, sys adm wrote: > I do hate to write s/^\s+|\s+$//g for each and each time,just got tired of it. > So I hope perl can have that a string operator, since many script languages > have that, and it's used universally. Write the subroutine once, and then you won't have to do much more typing than you would in a language that has that as a built-in function. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Convert Array's into hashes
On Thu Aug 06 2009 @ 11:19, jet speed wrote: > @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 and @array2 as values. use warnings; use strict; my @array1 = qw/D_101 D_102 D_103 D_104/; my @array2 = (0, 1, 2, 3); my %hash = map { $array1[$_] => $array2[$_] } (0..$#array1); This would work, but in practice if @array2 held literally numbers from 0 to the upper index of @array1, then it's unnecessary. You could do it easily without a second array at all. If @array1 has numbers that aren't simply the index, then you could do it as above. Otherwise, try this: my @array1 = qw/D_101 D_102 D_103 D_104/; my %hash = map { $array1[$_] => $_ } (0..$#array1); Also you should always use warnings and strict to catch errors. You should be seeing errors about how you're trying to initialize the two arrays (barewords in @array1 and missing operators - the commas - in @array2). > How can I recall only certain keys and their corresponding values of hashes > ex : if D_103 then print " D_103 value is 2" > ex :if D_101 then print "D_101 value is 0" I'm not quite sure what you have in mind here, but in general printing a key/value pair if you have the hash key in a variable (say $foo) is as easy as this: print "The value of $foo is $hash{$foo}\n"; In this case, perhaps you narrow down the records you care about and then put those into an array first: my @important_records = qw/D_102 D_104/; for my $item (@important_records) { print "The value of $item is $hash{$item}\n"; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: 'Join' query
On Fri Aug 07 2009 @ 4:03, jet speed wrote: > Hi, > > 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"; The function join works on lists not scalars. This would do what you want: my @important_numbers = (1..5); my $out = join ':', @important_numbers; print $out, "\n"; Alternatively, if for some reason your application gets the string '1 2 3 4 5' as a single item, you could split it first (on whitespace) and then join the list that split produces: my $string = '1 2 3 4 5'; my $out = join ':', split /\s/, $string; print $out, "\n"; My guess is that you don't really want the data in a string to begin with, but sometimes you are getting it from somewhere else. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ||= operator
On Fri Aug 07 2009 @ 2:55, Admin wrote: > Hi there, > > is there a page that explains the ||= operator and similar operators? > google is not quite finding the special characters in the first 10 hits. Google and punctuation don't mix well, apparently. In any case, try perldoc perlop in a terminal or online: http://perldoc.perl.org/perlop.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: IO::File close on undef behaviour?
On Wed Aug 12 2009 @ 11:27, Philip Potter wrote: > If $fh goes out of scope, will the file be automatically closed? Yup. From perldoc perlopentut: Another convenient behavior is that an indirect filehandle automatically closes when it goes out of scope or when you undefine it: sub firstline { open( my $in, shift ) && return scalar <$in>; # no close() required } See the whole section "Indirect Filehandles" for more. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
A side note [was Re: Attentipn Please!! Need A Perl script to yada yada]
On Mon Aug 17 2009 @ 4:09, Uri Guttman wrote: > > "I" == Ian writes: > > I> Unfortunately I'm not an expert. I just read a few books and this list > etc. > > a couple of things. it is good that you are offering to help but as you > claim not to be an expert, it can hurt more than help. there are plenty > of experts on this list who can help and fixing up weak code offered > from beginners makes our work even harder. This has come up before, as I recall, but either way, I have to disagree. There are a LOT of us here who are far less than expert, but more than novice users. I don't agree that we shouldn't offer our (presumably less than expert) code. If anything, it can be a good way for us to learn as well. To clarify, I think anyone (expert or otherwise) should only offer code that they feel good about. If you have no idea how to tackle a problem, then it would be unhelpful to spew out some random code. On the other hand, your response seems to go too far in the other direction (advice and ideas, sure, but no code except from experts). One other thing worth saying: Ian seems to me to display the habit that a lot of first-time (or rare) posters do of over-apologizing for an answer. I do it myself here and on other forums, and I see it in my students all the time. It's a pretty natural way to try to deflect potential criticism. (Well, I'm not really sure, this is probably wrong, but...) I mention this because we shouldn't let it prejudice us against the answer. Again, I think there's room for non-experts, even in code. Just my two cents, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script to compare dates
On Tue Aug 18 2009 @ 7:55, Mihir Kamdar wrote: > I dont have Datetime module installed. Is there a way without using > DateTime?? I don't want to be glib, but I can see at least two broad possible options: (1) Install DateTime (it's very worth it). (2) Rewrite all the relevant code from DateTime (it's very not worth it, except perhaps as a learning exercise or masochism). More seriously getting date arithmetic right can be very hard. Your particular need doesn't sound too complicated now (compare two dates to a fixed date), but I still wouldn't choose to recreate a solution for date parsing and comparison when there are good solutions easily available at CPAN. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Business::UPS should be fixed or removed.
On Sat Aug 22 2009 @ 10:30, Rick Bragg wrote: > Hi, > > As far as I can tell, this perl module returns bogus numbers that have > nothing to do with the real prices from UPS and should be done away with > or fixed. If you use this, beware, check out your prices, will all be > low. > > Rick Thanks for the warning, but have you filed a bug against the module on CPAN? That's really the best place to warn people (rather than this one list). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Totally lost on how to get the argv of Perl
On Sun Aug 23 2009 @ 9:06, Andrew Steinborn wrote: > Shawn H. Corey wrote: > >Andrew Steinborn wrote: > >>I need to know how to get the arguments passed to Perl. I'm > >>using the ActiveState built version of Perl on Windows Vista. > >> > > > >Perl loads the command-line arguments into the special variable @ARGV > > > >See `perldoc perlvar`. > > > > > Thanks. I figured it out reading the HTML docs. I'm don't know exactly how ActiveState is set up, but in general the HTML docs (say at http://perldoc.perl.org/) should always be available in a terminal via perldoc. Obviously, most people now have internet access at all times, and many people probably prefer to read online, but I find quick lookups (and searches) in the terminal often save time. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: one liner in Windows to replace string
On Mon Aug 24 2009 @ 4:45, Tony Esposito wrote: > perl -p -i.bak -e 's/CONSTANT/VARIABLE/' C:\test.txt > > Trying to replace a string with this one line perl ... in Windows it does not > seem to work ... > > File test.txt contents is ... > > CONSTANT 100 > CONSTANT 200 > > nothing changes ... acts as if it does not 'see' the CONSTANT string. > > Help because it looks like it should work !!! I don't use Windows, but my first thought is that it's a quoting problem. Try replacing the single-quotes with double-quotes in the command line: perl -i.bak -ple "s/CONSTANT/VARIABLE/" C:\test.txt See here for more one-liner tips: http://sial.org/howto/perl/one-liner/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: one liner in Windows to replace string
On Mon Aug 24 2009 @ 8:08, Tony Esposito wrote: > Looks good but it bombs ... the Perl interpreter crashes from the DOS prompt > ... using version 5.10.0 build 1005 from ActiveState. > > But it was better than what I had, that's for sure > > This makes for a bit of a mind teaser thanks to it being on Windoze ... :-) Ok, not to be a jerk, but look at it this way: it's clear that Windows + one-liners are not going well. In the time we've all gone back and forth on this, you could have written a 10 line script and run it about 20 times. Pick your battles, I say. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: source code for builtin functions
On Thu Aug 27 2009 @ 4:55, Shawn H. Corey wrote: > Nowadays, Linux comes with Perl but not its documentation. To > download it, start your favourite package manager and download the > package "perl-doc" Also, since some of it refers to the Syscalls, > you may want its documentation. Its package is "manpages-dev" I'm curious what you mean by "nowadays" here. In my experience, it's only Debian (and Debian descendants) that ships without documentation for Perl. I guess I'm wondering if (1) lots of other distros do this too or (2) Ubuntu does it (as a Debian child), and in your mind Ubuntu _is_ Linux nowadays. Just curious, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: source code for builtin functions
On Thu Aug 27 2009 @ 2:40, heyi xiao wrote: > I knew perl is written in C, but I am still interested in > checking the C source for some builtin function directly. Is there any good > way > to go? If you browse to this site, you can download the source code for whatever version of Perl you're working with and read away: http://www.cpan.org/src/README.html Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl6
I've been following Perl6 via these links. You may find some good reading at one or another of these: http://szabgab.com/perl6_tricks_and_treats.html http://perlgeek.de/blog-en/perl-5-to-6/ http://perlgeek.de/blog-en/perl-6/ You can also find some interesting projects on Github that are using Perl6. Here's two starting places there, though there are many others: http://github.com/perl6/ http://github.com/viklund/november/tree/master An easy way to get started is to download the latest version of Rakudo, build it (and Parrot), and then try out a simple program: ./perl6 -e 'say "hello world!"' I'll admit that I have done only slightly more than that so far, but if you're curious, it easy to build a perl6 interpreter. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: accessing chars in a string
On Tue Sep 01 2009 @ 10:44, Steve Bertrand wrote: > A good place to reference regex is [1]. > > [1]: http://perldoc.perl.org/perlretut.html I will throw in my two cents and mention that if you are starting regular expressions, you may find perldoc perlrequick a little more gentle, as an introduction: http://perldoc.perl.org/perlrequick.html Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Ternary operator
On Fri Sep 11 2009 @ 4:16, Chas. Owens wrote: > I love perldoc, but it does not document the language nearly as well > as Programming Perl. Of course, that might be why perldoc is free and > Programming Perl costs roughly $50 USD (and weighs a ton). There's also the problem that Programming Perl was last updated for Perl 5.6, I believe. (5.8?) Unfortunately, it seems like O'Reilly has given up on Perl... -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: "Tell your lawyers" [Was - Re: "Out Of Memory"]
On Sun Sep 20 2009 @ 9:01, Shawn H Corey wrote: > Ajay Kumar wrote: > >__ > >This communication contains information which is confidential. It is for the > >exclusive use of the intended recipient(s). If you are not the intended > >recipient(s) please note any distribution, copying or use of this > >communication or the information in it is strictly prohibited. If you have > >received this communication in error please notify us by e-mail or > >by telephone (as above) and then delete the e-mail and all attachments and > >any copies thereof. > >__ > > Tell your lawyers that such a pronouncement on a public mailing list > is illegal and resented. Ok, I'll bite: do you really mean to say that it's a crime somewhere to put this bullshit drivel into an email and then send that mail to a public list? Annoying, sure. Pointless, sure. Non-binding, sure. But a crime? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: "Tell your lawyers" [Was - Re: "Out Of Memory"]
On Sun Sep 20 2009 @ 10:13, Shawn H Corey wrote: > Telemachus wrote: > >Ok, I'll bite: do you really mean to say that it's a crime somewhere to put > >this bullshit drivel into an email and then send that mail to a public > >list? Annoying, sure. Pointless, sure. Non-binding, sure. But a crime? > > > > Speeding is illegal but not a crime. Not all laws are part of the > criminal code. I think that my meaning was reasonably clear, but apparently not. Is it part of hte civil code then? Is there some law - be it criminal or otherwise - against putting the silly disclaimers into emails and then sending those emails to a public mail list? I'm genuininely curious (and find it a little hard to believe). -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: "Tell your lawyers" [Was - Re: "Out Of Memory"]
On Sun Sep 20 2009 @ 12:17, Shawn H Corey wrote: > Rodrick Brown wrote: > >These disclaimers are requirements for anyone working in the > >securities industry. There isn't much the poster can do about this and > >shouldn't be bashed for this. Many of these disclaimers are > >automatically appended to everyones out going emails so there isn't > >really anything he could have done. > > Of course, if a corporation, rather than an individual, does it, it > legal...not. > > "My boss made me do it" ranks right up there beside "The devil made > me do it" or "I was just following orders". None other these > excuses are acceptable. Let's try to at least read what the other person said. Rodrick didn't touch the legality issue. He simply pointed out that in many cases, if you work at company X and you send mail out from your email account, the disclaimer will get added to your mail. At many companies, it's also difficult and forbidden to access any non-company email while at work. Perhaps such people shouldn't email this or any other public list. I'm not going to weigh in on that. But as a practical matter, many people are stuck with those disclaimers if they want to use email from work in a straightforward manner. The disclaimers are clearly bogus, useless and annoying. I agree. But are they really that hard to ignore? Hint: they're at the bottom of the mail. Just stop reading. As for "I was just following orders," that's a pretty quick (if implicit) confirmation of Godwin's law. Thanks for helping to make the internet predictable. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: best way to get number of elements in list value
On Tue Sep 22 2009 @ 10:56, Chas. Owens wrote: > On Tue, Sep 22, 2009 at 09:40, Bryan R Harris > wrote: > > Can you explain how perl interprets this? I would've incorrectly thought: > > > > 1) "() = func_that_return_list_value" tries to assign the list to "()" > > which perl would complain about. > > > > 2) Then assign the result to $size, which it wouldn't like either. > > > > Just when you think you're starting to understand perl... > snip > > The number of "catcher" elements in a list does not need to be equal > to the number of "thrown" items: > > my ($x, $y) = (1, 2, 3); > > List assignment behaves differently in list and scalar contexts. In > list context, it returns the list that was successfully assigned to > variables. In scalar context, it returns the number of items that > tried to be assigned. So, in > > perl -le '$z = ($x, $y) = (qw/a b c/); print "$x, $y, $z"' > > $z is 3 (because there were three items in RHS of the assignment), $x > is "a", and $y is "b". "c" is silently discarded. All of this makes sense, but I have to admit I find it odd that the following doesn't even produce a "void context" warning: my @array = (1, 2, 3); my $num = () = @array; print $num, "\n"; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Change character code 160 to 32
On Sun Oct 04 2009 @ 3:28, Shawn H Corey wrote: >> If you're on Linux, type: man ascii Works on OSX, too. And thanks for the tip. That's handy, and I never knew it was there. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: great new installation package - how to override /usr/lib/perl5/site_perl/5.8.8?
On Mon Oct 05 2009 @ 8:46, Charles Smith wrote: > I'm trying to install UR-v0.12 - and encountered a great wizard. But I don't > have root access on my machine. I get > > You are not allowed to write to the directory > '/usr/lib/perl5/site_perl/5.8.8' > > even though I'd entered > > Your choice: [] PREFIX=~/lib/perl > > > Can somebody please explain to me how I can use ~/lib/perl instead of > something in superuser areas? Different modules build scripts will sometimes require different variables be set in order to override the default installation locations. A good general solution is Local::Lib: http://search.cpan.org/~apeiron/local-lib/ Hope this helps. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: adding populations
On Tue Oct 06 2009 @ 11:24, Jesus Fernandez wrote: > Dear friends, > > I'm working in a genetic drift simulation and I want to add a second > population to my script, any suggestions how to do that? Is this a follow-up to a previous question? Either way, please keep in mind that we don't have any access to your files or your data except what you tell us. Nobody will be able to help you unless you share some more information. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Learning Perl Student Workbook
On Sun Nov 01 2009 @ 10:51, raphael() wrote: > Hi, > > I just finished reading 'Learning Perl' & I was wondering if someone > could point me to the book "Perl Study Guide", > also called "Learning Perl Student Workbook". It's a companion book to > "Learning Perl" but is not available in my country. > > I was hoping if someone could give me a link to a soft copy (an ebook). I hope that you're not looking for a pirated pdf copy. Amazon ships all over the world, don't they? http://www.amazon.com/Learning-Perl-Student-Workbook-brian/dp/0596009968/ref=sr_1_1?ie=UTF8&s=books&qid=1257076787&sr=8-1 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Learning Perl Student Workbook
On Sun Nov 01 2009 @ 12:32, Parag Kalra wrote: > >>>google doesn't turn up any soft copies ?? Is any electronic copy of this > book even there? > > Even I am not sure if there is any soft copy available or not...Lets wait > till we get input from other members of the mailing list... > > Cheers, > Parag I'm not entirely sure, but I think that this book was only every for sale as a softcover. In any case, Amazon does have softcovers: http://www.amazon.com/Learning-Perl-Student-Workbook-brian/dp/0596009968/ref=sr_1_1?ie=UTF8&s=books&qid=1257076787&sr=8-1 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Learning Perl Student Workbook
On Mon Nov 02 2009 @ 9:33, Parag Kalra wrote: > Hey Folks, > > This thread was about book - 'Learning Perl Student Workbook' and not the > book - 'Learning Perl' > > So is there a way we can buy genuine/official/legal ebook version of > 'Learning Perl Student Workbook' from somewhere. > > If yes then please redirect us to the same. > > Cheers, > Parag I feel a bit like Echo, but here's my third time saying this in one thread. You can get the workbook from Amazon here: http://www.amazon.com/Learning-Perl-Student-Workbook-brian/dp/0596009968/ref=sr_1_1?ie=UTF8&s=books&+qid=1257076787&sr=8-1 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Learning Perl Student Workbook
On Mon Nov 02 2009 @ 7:14, tom smith wrote: > use strict; > use warnings; > > $\ = "\n"; > > my @book_types = ('hard cover book', 'soft cover book', 'ebook'); > > if ('soft cover book' eq 'ebook') { > print 'yes'; > } else { > print 'no'; > } > > --output:-- > no Right. The original post in this thread (it was from sometime in 1960 it feels like) mentioned that the book "wasn't available" for purchase by the original poster (raphael), and I quote: "[the book] is not available in my country." My responses have been directed at that. The book is available from Amazon, and I believe (still - all these posts later) that Amazon ships books all over. That said, an e-book would probably be even easier (and possibly significantly cheaper, depending on shipping). As far as I know, however, the workbook for Learning Perl has never been available as an ebook. I think that brian d foy originally sold it himself, and only later did it become available through stores. At least, that's what I can guess from this page: http://www.theperlreview.com/learning_perl_study_guide/ brian doesn't post here much (ever?), but Randal may chime in. I'm done. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: can I wipe cpan off my computer?
On Sat Nov 07 2009 @ 8:27, Shawn H Corey wrote: > The cpan program is little more than a shell for CPAN.pm. When you > first start cpan, it says to install Bundle::CPAN and a newer version of > CPAN.pm. These modules do not play nice. Last time I installed them, I > could get cpan to work at all. So, the question is: did you upgrade > these modules? Let me see if I'm reading this right: (1) You start cpan. (2) It tells you to install Bundle::CPAN and a new version of CPAN.pm. (3) You do so, and they break cpan? Wow. @Tim: I've had pretty good experiences with cpanp on OSX. You might try taking a look at that instead of cpan. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Is it necessary to open the file again to read its contents.
On Tue Nov 17 2009 @ 11:23, Parag Kalra wrote: > Now if want to again the loop through the contents of the file I was not > able to do the following again: > > while ( ) { > print "$_\n"; > } > > Instead I had to first close the previous file handler and the again open > the file to loop through the file i.e few more following steps: > > close FILE; > > open FILE, "my_file.out"; > while ( ) { > print "$_".""."$_\n"; > } > close FILE; > > Can't this again closing and opening of file avoided while looping through > the file? Part of what happens when you go through a file line by line using readline (in your code <> is simply a prettier way of writing readline) is that Perl keeps track of where you are in the file. That way, successive calls get successive lines. Once you've gone through the whole file, you're at the end, so you can't simply pick up and read again. However, you can use the function seek to reset the pointer to the top of the file: seek(FILE, 0, 0) See perldoc -f seek. While we're not on the subject, you shouldn't be using bareword filehandles like FILE, but you *should* always check that the file opened properly. See the documentation for open for how to use lexical filehandles, but it would look something like this: open my $fh, '<', 'my_file.in' or die "Can't open 'my_file.in' for reading: $!"; while (<$fh>) { # do stuff to the line } See perldoc -f open and perldoc perlopentut for more. (You're also overquoting. I think someone mentioned it to you, but I'll throw in my two cents there too.) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: udp server
On Tue Dec 01 2009 @ 1:09, Rene Schickbauer wrote: > Take a look at > > I highly recommend that you buy the Perl Cookbook, most of these > problems (or rather the solutions for them) for these kind of tasks > are in there ;-) I agree that the Perl Cookbook is an excellent resource. Please don't post to pirated online copies of that (or any other) book. Thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/