Re: Handling special characters in peoples names in XML
From: Gregory Machin g...@linuxpro.co.za Thanks Terry for responding. The files are very big and contain data I'd prefer not to be out in the wild. what parts of the file would be helpful , I can provide the lines with the text and say heard part of the xml ?? Thanks G Yep, that should be enough. The first line or two and a bit with the text as attached files. Just make sure you do not change the encoding in the process. You may check that with a heda editor Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Handling special characters in peoples names in XML
From: Gregory Machin g...@linuxpro.co.za I'm debugging an application written in Perl that converse data exported from the Nessus security scanner in xml format. I have narrowed down the bug to an issue with special characters in names that are in the file such as Fr~A©d~A©ric and Gr~A©goire , thus ~A© are most likely the guilty parties. What is the best and most simple way to handle this ? From a quick google it looks like I should convert the file to UTF8 format , would this be correct ? Thanks Greg Looks like the data already is utf8, but the header of the XML specifies otherwise. How do you parse the data? Can you give us a short example file? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Variables in $Excel-Workbooks-Open
Dear All, I am having an XLSX file in server and my OS in Win7. The first open statement is working fine in which we have give the actual file name. 2nd open function is not working where we have given the file name as variable. Please help in resolving this error. use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Excel'; $emfile=02896787; $Excel = Win32::OLE-GetActiveObject('Excel.Application') || Win32::OLE-new('Excel.Application'); $Excel-{'Visible'} = 0;#0 is hidden, 1 is visible $Excel-{DisplayAlerts}=0;#0 is hide alerts my $mBook = $Excel-Workbooks-Open ('pchns2003z\SPECIALIZED_SERVICES_I\AnI\Embase\Pull files_IRNPD\inventory\02896787.xlsx'); # open Excel file my $meBook = $Excel-Workbooks-Open (pchns2003z\\SPECIALIZED_SERVICES_I\\AnI\\Embase\\Pull files_IRNPD\\inventory\\$emfile.xlsx); # open Excel file There is no problem with the variable interpolation or backslashes. The two strings are the same: my $emfile=02896787; my $mBook = 'pchns2003z\SPECIALIZED_SERVICES_I\AnI\Embase\Pullfiles_IRNPD\inve ntory\02896787.xlsx'; my $meBook = pchns2003z\\SPECIALIZED_SERVICES_I\\AnI\\Embase\\Pullfiles_IRNPD\ \inventory\\$emfile.xlsx; print $mBook\n$meBook\n; print ($mBook eq $meBook ? the same : different); The problem lies elsewhere. If you ask Excel to open the same file in two instances at the same time it will complain that it's already open. Try to open a different file :-) Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Spreadsheet::WriteExcel - multi-coloured text in cells
From: Dr.Ruud rvtol+use...@isolution.nl On 15/05/2013 21:35, David Precious wrote: On Wed, 15 May 2013 10:34:02 +0100 Gary Stainburn gary.stainb...@ringways.co.uk wrote: Is it possible to write text cells where part of the string is highlighted in red? If so, how can I do it? I'm fairly sure the format of a cell applies to the whole content of that cell - can you do what you're asking for in Excel or similar yourself? If not, then I very much doubt you can do it via Spreadsheet::WriteExcel. There is cell formatting and there is text formatting. Each character can basically have its own background-color, foreground-color, font, font-weight, etc. And beyond that, each cell can contain an object, like a Word-document. But you don't need to go there to achieve what you want. First find out how you would do it in its internal language (VB?), and then port that. Knowing how it's done in VB For Applications would help if he was controlling an instance of excel via Win32::OLE. Then there would be a way to port that code to Perl. When using Spreadsheet::WriteExcel, the capabilities of whatever Excel he happens to have installed are at most an upper bound of features. Not something that could be taken for granted. If something is not possible via Excel, it most probably will not be possinble using S::WE, but the fact that Excel can do something doesn't say anything about S::WE. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Any alternative for substr() function
From: timothy adigun 2teezp...@gmail.com On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Nope. It would work just fine as long as the bits he's interested in are fixed lengh and are on fixed positions. The length of the uninteresting trailing stuff is irrelevant. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Win32 - Killing Processes - update possible solution
From: Jonathan Harris jtnhar...@googlemail.com As it seems that Win32::Process::KillProcess is having difficulties killing a hanging process, I thought that it would probably make sense to ask the system to do it directly So, in the sub 'kill_it', I have replaced the line Win32::Process::KillProcess ($new_pid, \$exitcode); with system 'Taskkill /PID ' . ($new_pid); I am using 'system' rather than 'exec' as it returns a success status; 'exec' is silent in this respect The fairly confusingly named fuction exec() never returns! It's supposed to be used if you are done executing your program and want to switch to executing a different one ... usually after you fork()ed ... that is cloned the process. The way processed are started in unix is a little ... awkward. Instead of telling the system you want to execute some program with some parameters, you are supposed to split in two and in one of the clones, after you are finished setting things up, morph into another program. Kinda hacky. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Problems in Mail::Sender on sending a large attachment file
I have used Mail::Sender for a number of years and I have had to move onto new VM for Processing. The Linux is Red Hat Enterprise Linux Server release 5.4 (Tikanga). Perl is v5.8.8 built for x86_64-linux-thread-multi Mail::Sender is 8.21 I am only sending attachment file along with a couple of lines of text, BUT somehow in doing the send, I end up with the following error: Unknown encoding '522' at /usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm line 96 FYI, the problem has been fixed by version 0.8.22, thanks to a patch by allad...@netsafe.cz (bug 78094 in CPAN RT) Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Fast XML parser?
From: Octavian Rasnita orasn...@gmail.com I forgot to say that the script I previously sent to the list also crashed Perl and it popped an error window with: perl.exe - Application Error The instruction at 0x7c910f20 referenced memory at 0x0004. The memory could not be read. Click on OK to terminate the program I have created a smaller XML file with only ~ 100 lines and I ran agan that script, and it worked fine. But it doesn't work with the entire xml file which has more than 200 MB, because it crashes Perl and I don't know why. And strange, but I've seen that now it just crashes Perl, but it doesn't return that Free to wrong pool error. Octavian That must be something either within your perl or the XML::Parser::Expat. What versions of those two do you have? Any chance you could update? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Fast XML parser?
From: Octavian Rasnita orasn...@gmail.com To: beginners@perl.org Subject:Fast XML parser? Date sent: Thu, 25 Oct 2012 14:33:15 +0300 Hi, Can you recommend an XML parser which is faster than XML::Twig? I need to use an XML parser that can parse the XML files chunk by chunk and which works faster (much faster) than XML::Twig, because I tried using this module but it is very slow. I tried something like the code below, but I have also tried a version that just opens the file and parses it using regular expressions, however the unelegant regexp version is 25 times faster than the one which uses XML::Twig, and it also uses less memory. If you think there is a module for parsing XML which would work faster than regular expressions, or if I can substantially improve the program which uses XML::Twig then please tell me about it. If regexp will still be faster, I will use regexp. You did not specify what do you want to do with the lexemes anyway you might try something like this: use strict; use XML::Rules; use Data::Dumper; my $parser = XML::Rules-new( stripspaces = 7, rules = { _default = 'content', InflectedForm = 'as array', Lexem = sub { #print Dumper($_[1]); print $_[1]-{Form}\n; foreach (@{$_[1]-{InflectedForm}}) { print $_-{InflectionId}: $_-{Form}\n; } }, } ); $parser-parse(\*DATA); __DATA__ ?xml version=1.0 encoding=UTF-8? Lexems Lexem id=1 ... XML::Rules sits on top of XML::Parser::Expat so I would not expect this to be 25 times faster than XML::Twig, but it might be a bit quicker. Or not. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl Code
From: Chris Nehren c.nehren/beginn...@shadowcat.co.uk On Wed, Aug 29, 2012 at 09:59:22 -0700 , John SJ Anderson wrote: On Wednesday, August 29, 2012 at 9:46 AM, Ashwin Rao T wrote: 1)Check if IP address is in the range 172.125.1.0 and 172.125.25.0 using only return functions regular expressions in Perl. 2)Check if the name is valid (has atleast 3 letters and one vowel) using only return functions and regular expressions in Perl. 3)Check if email address is valid using only return functions and regular expressions in Perl. 4)Convert the number into words using only return functions and regular expressions in Perl. (15 = one five) I'm pretty sure the instructor in the class you're taking would prefer that you do your own homework… I'm pretty sure the instructor doesn't know Perl or regular expressions if they're asking for those things to be done with only regex. At least three items on that list are best done with CPAN modules. My advice is to drop the class now and get a refund, if at all possible. The fact that there's a module for something doesn't necessarily mean it's not a good homework assignment. Especially if you restrict both the allowed constructs and the task. Now in this case the 3) is surely ill defined ... even if valid meant just syntacticly valid the RFC is crazy enough to make this nondoable. Unless of course at the class they spoke about a specific definition of valid. It might be a trick question though with the best answer similar to a simple check might look like this: /.../, but it will allow some invalid addresses and reject some rare valid ones. A more restrictive solution still matching the vaste majority of email addresses in the wild would be /... .../. For validation according to the RFT, module X::Y may be used. Actually ... what percentage of websites doing email address validation in their forms do you think validate according to the RFC? 0.001%? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Mail::Sender with SSL
From: Chris Nehren c.nehren/beginn...@shadowcat.co.uk On Thu, Aug 16, 2012 at 00:05:56 +0200 , Jenda Krynicky wrote: From: Chris Nehren c.nehren/beginn...@shadowcat.co.uk On Tue, Aug 07, 2012 at 17:38:57 + , Thomas Dean wrote: Hi there, I have succeeded in sending mail to my SMTP server with Mail::Sender without SSL. But now I'm wondering how to do that with SSL, for example, GMail. After reading the doc, I set TLS_required to 1 when I'm calling Mail::Sender-new, but nohing works. I tried to debug the program but found nothing different whether I turn TLS_required on or not. You should look at Email::Sender::SMTP::TLS instead--it's the de facto, mature way of sending email through TLS SMTP servers with perl, and is actively supported. Mail::Sender reinvents a lot of wheels, poorly, as you are finding. It reinvented a lot of wheels that were not available at the time it was written. The fact that there is a specific module now doesn't mean it had been available or working under the target operating systems always. Email::Sender is still the right tool to use, and actually works. It probably sends more mail in a day than you ever will*. Having been the basis of the Hotmail service Mail::Sender sent more mail you ever will. By order of several magnitudes. Not sure what they use now, but they had been using Mail::Sender for several years as could have be seen in the mail headers. Several other similar services used or use the same module. As for your spurious working under the target operating system always claim, Email::Sender::Transport::SMTP::TLS has a flawless CPAN testers report card, visible here: http://www.cpantesters.org/distro/E/Email-Sender-Transport-SMTP-TLS.html#Email-Sender-Transport-SMTP-TLS-0.10 I can uninvent the wheels I had to invent back in the day because no wheels had been available back then or those that were available did not work under operating systems I had to support. The first version of Email::Sender was released 2008-12-10, the first version of Mail::Sender was released sometime in 1998! That's ten years of CPAN growth! The SYNOPSIS provides all (or very nearly all) the code Thomas needs, with very little tweaking besides configuration. How can it possibly be easier? This use the old, bad tool because it's what the OP started with approach leads only to pain and suffering. * having put it into production at a large ESP that handles thousands of per day, I'm pretty sure this is the case. I'm incredibly impressed ... Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Mail::Sender with SSL
From: Chris Nehren c.nehren/beginn...@shadowcat.co.uk On Tue, Aug 07, 2012 at 17:38:57 + , Thomas Dean wrote: Hi there, I have succeeded in sending mail to my SMTP server with Mail::Sender without SSL. But now I'm wondering how to do that with SSL, for example, GMail. After reading the doc, I set TLS_required to 1 when I'm calling Mail::Sender-new, but nohing works. I tried to debug the program but found nothing different whether I turn TLS_required on or not. You should look at Email::Sender::SMTP::TLS instead--it's the de facto, mature way of sending email through TLS SMTP servers with perl, and is actively supported. Mail::Sender reinvents a lot of wheels, poorly, as you are finding. It reinvented a lot of wheels that were not available at the time it was written. The fact that there is a specific module now doesn't mean it had been available or working under the target operating systems always. Enough plesantries, Tom, what exactly did you try an how exactly did it fail? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to get the file handle of a scalar
From: Shlomi Fish shlo...@shlomifish.org Hi Thomas, On Mon, 30 Jul 2012 20:23:58 +0800 Thomas Dean tomdean...@gmail.com wrote: Hi there, I'm wondering how to get the file handle or a reference of a file object of a scalar in which stores a string. Starting from relatively recent versions of Perl, you can simply do: use autodie; my $buffer = Hello World\nGood morning\nPretty foo\n; open my $fh_to_string, '', \$buffer; And then do $fh_to_string and other operations. Just to prevent confusion ... the use autodie is not needed to be able to open a filehandle into a string. It should not have been in the example, because it's totally irrelevant to the point at hand. It forces some Perl builtins to throw an exception instead of reporting success or failure using their return values. Some people believe this makes the code more robust. But then people believe all kinds of things. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Concatenation in Perl
From: Paul Johnson p...@pjcj.net You need a mixture of the two approaches: map to prepend not in: and join to join them. my $query = join and , map not in:$_, @folders; @folders = ('one', 'two'); my $query = not in: . join( and not in:, @folders); print $query; will be quicker. no need to map and join just because you need some text even before the first value. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Very Sluggish Code
From: GlenM glenmill...@gmail.com # Read them into an array my @files_in_dir = grep { /xml/ } readdir(DIR); You want all files with lowercase xml anywhere the the name? Really? I think you want my @files_in_dir = grep { /\.xml$/i } readdir(DIR); instead. That is files with extension .xml. closedir DIR; # connect to database and create parser object my $dbh = DBI-connect (DBI:mysql:can_us_ratecenters, , xx, { RaiseError = 1, PrintError = 0}); # clear the database - new DIDs coming in $dbh-do ('TRUNCATE TABLE rc_city_town'); #Now the fun begins - read each file and put it in the database foreach my $f (@files_in_dir) { open IN, $f; my $xp = XML::XPath-new (filename = ./$f); my $nodelist = $xp-find (//row); foreach my $row ($nodelist-get_nodelist ()) { $dbh-do ( INSERT IGNORE INTO rc_city_town (state_prov, city_town, did_number) VALUES (?,?,?), undef, $row-find (state)-string_value (), $row-find (ratecenter)-string_value (), $row-find (number)-string_value (), ); Do split this into two calls my $sth = $dbh-prepare(INSERT IGNORE INTO rc_city_town (state_prov, city_town, did_number) VALUES (?,?,?)); just below the connection to the database and $sth-execute( $row-find (state)-string_value (), $row-find (ratecenter)-string_value (), $row-find (number)-string_value (), ); in the foreach loop. Then you most probably want to turn the autocommit off my $dbh = DBI-connect (DBI:mysql:can_us_ratecenters, , xx, { RaiseError = 1, PrintError = 0, AutoCommit = 0}); and then call $dbh-commit or die $dbh-errstr; once every (say) 1000 rows and at the end of each file. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Book Recommendation - XPath, XML,SQL, XQuery
From: David Christensen dpchr...@holgerdanske.com On 04/17/2012 11:04 PM, flebber wrote: I also saw Perl XML - http://shop.oreilly.com/product/9780596002053.do These will probably both be good references I haven't read Perl and XML (nor XML and Perl). However, I am working on a project that could benefit from XML. So, I'll need to explore that path soon enough. but was a little concern that the publication dates were 2000 and 2002. Perl and the core technologies involved have had significant advancement in that time. Don't let the publication dates put you off. Good ideas and good books are enduring. Yes, there are updates; but you won't understand the updates if you don't understand what is being updated in the first place. While generally this is a good idea, in this particular case the target was moving so fast that I would not recommend that book. Quite a few modules described in the book are long gone, others appeared, the Unicode handling in Perl has undergone big changes in the meantime, ... Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Template::Toolkit question
To: beginners@perl.org From: Manfred Lotz manfred.l...@arcor.de Subject:Template::Toolkit question Date sent: Mon, 9 Apr 2012 20:28:14 +0200 Hi all, Let's say I use Template:Toolkit like this: -snip--- #! /usr/bin/perl use strict; use warnings; use Template; my $variables = { nrme = Manfred, }; my $cmd = 'Hi [% name %], how are you.'; my $template = Template-new(); $template-process(\$cmd, $variables) or die $template-error(), \n; -snap--- and accidentally I have a typo in $variables (nrme instead of name). The output is: Hi , how are you. IMHO, this is really bad. I would like to get an error saying that a variable could not be substituted. Perhaps this? http://search.cpan.org/~abw/Template-Toolkit- 2.24/lib/Template/Manual/Config.pod#STRICT Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sending files efficiently with Net::SMTP
From: mailing lists listas.cor...@yahoo.es I have a perl (Ver. 5.10.0) program running over an old machine which send messages with this code: my $smtp = Net::SMTP-new($dstMailServer, Timeout=10, Debug=0,); unless(defined($smtp)){ syslog LOG_INFO, id:%s error: unable to connect with %s, $myid, $dstMailServer; exit $EX_TEMPFAIL; } $smtp-mail($sender); $smtp-to($recipient); $smtp-data(); my $line; open INPUTFILE, , $outfile or die couldn't open $outfile; while(defined($line=INPUTFILE)){ $smtp-datasend($line); } close INPUTFILE; $smtp-dataend(); $smtp-quit; since the machine belongs to a third party I have no possibility to install perl modules (no internet connection, compilers, etc) like Slurp. So sending files in the MB range is very slow. Anyone know how to optimize (if possible) this code? Read (and send) the files by blocks (8kb sounds reasonable) instead of lines. See perldoc -f read not sure it'll help much though. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: ASCII/binary endline character trouble
Date sent: Sun, 25 Mar 2012 15:45:11 -0700 (PDT) I write CGI scripts for my website in PERL. When I used to upload them with my FTP program I made sure to do so in ASCII mode rather than binary. My host made me switch to sFTP however. I use FIlezilla, and can't for the life of me find out how to choose the mode on that. Unfortunately, binary is the default mode. I don't like programming when the file displays ASCII endline characters. I'd rather see clear, distinct lines rather than one long line broken up with those vertical rectangles. When I download a script from my site for editing it looks terrible. Any even remotely decent editor handles unix line edings just fine. What are you using to edit/view the files??? Notepad? If you want something small and generic try http://www.scintilla.org/SciTE.html if you want something bigger and with more features try http://padre.perlide.org/ Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Access class symtab by dereferencing an object
Date sent: Sat, 03 Mar 2012 14:42:35 -0500 From: Steve Bertrand steve.bertr...@gmail.com I've been writing a program that will perform extra work for diagnostics upon each method call. As of now, I need to write a call to an outside function manually into each method. To automate this so the original methods don't need to be modified, I'm going to scoop up the code globs, modify them, then reinstall them back into the class. http://search.cpan.org/search?query=Devel::TraceSub http://search.cpan.org/search?query=Devel::TraceCalls http://search.cpan.org/search?query=Devel::TraceFuncs = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: module for development
From: Brian Fraser frase...@gmail.com On Thu, Dec 15, 2011 at 10:09 AM, shawn wilson ag4ve...@gmail.com wrote: Strace stat(64) should do you. On Dec 15, 2011 8:03 AM, Ken Peng short...@gmail.com wrote: Hello, Which module could show the order of loading modules? For example, use Foo; use Bar; BEGIN { require A; } I want to know in what order Perl loads these modules. The order is Foo, Bar, A; Is it? What if Foo uses A? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML suggestions
From: Rob Coops rco...@gmail.com It really depends on what you are looking to do though, if you are aiming for just a simple thing with only a few messages then don't worry about XML::LibXML and go for XML::Simple which is more then enough in most simple cases ;-) Except that it's not so simple to set it up to give you consistent data structure with things like optional tag attributes and repeated tags. See http://www.perlmonks.org/?node_id=697036 I found that both Twig and Treebuilder are great if you are looking at modifying the XML (add extra nodes, alter existing nodes) but since they build a full tree structure for the XML file you are working with depending on the size and complexity of the file this could cause serious memory bloat, and even out of memory errors. XML::Twig (as the name suggests) is not supposed to build a full tree structure, but rather lets you work with parts of the document. The twigs. I personally believe XML::LibXML is overcomplicated, but some people seem to like it. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Nature of this list
From: Raymond Wan r@aist.go.jp 2011/4/25 Jenda Krynicky je...@krynicky.cz: From: Raymond Wan r@aist.go.jp After reading this, what came to mind is the problem of sexual and power harassment in the workplace, and maybe extending to other types of prejudices but maybe that is a stretch? Often, the person being accused might start with, I was just kidding or Hey! Both of us weren't taking it seriously! but sometimes that isn't the case. I'm tempted to say that whether or not it is harassment should depend on how the object of the action felt... The catch is that this basically means that: it's a crime whenever it's convenient for the victim. In some cases even just whenever it's convenient for a lawyer that happens to come by. Where there's money to be sued out, there's a crime. Yes, you are right. In the case of this list, there is (AFAIK) no gain for any victim to be a victim so we can safely assume the victims are victims, right? Nope. Not all gains are monetary. The people that are likely to ever give anything back to the community are much less likely to receive harsh treatment, than those that mistake the list for a free script writing service. Of course those that are starting to give advice on the list run the risk of having their advice dissected and in some cases corrected. Well, from what I've seen, the people that are being put down are not the ones that post their homework once but have been around for a few months and thought it was time to help someone out. The misunderstanding is that these people are not put down. Their answers (sometimes) are. And if they decide to take the critique of their code personaly then no amount of sweet words will help. And then there are three kinds of people. Those that take that as an oportunity to learn, those that misunderstand the critique and take it personally and those that take that as an oportunity to feel offended. The first kind will learn, the second will eventually learn as well ... and the last ... would do better to complain somewhere they can actually extort some money. Hm, sounds like you think that if the problem is ignored, it will go away? Some problems are real, some imaginary. The later kind is better ignored. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Nature of this list
From: Raymond Wan r@aist.go.jp Well, online bullying is a problem, but I don't think that saying Your Perl code sucks or Please don't post misleaing answers to people's Perl questions would qualify as online bullying. ... The point is this: some crimes hinge upon what's going on inside someone's head. What may not qualify as bullying to you may qualify for someone else. And, if that someone else files a complaint with the relevant law After reading this, what came to mind is the problem of sexual and power harassment in the workplace, and maybe extending to other types of prejudices but maybe that is a stretch? Often, the person being accused might start with, I was just kidding or Hey! Both of us weren't taking it seriously! but sometimes that isn't the case. I'm tempted to say that whether or not it is harassment should depend on how the object of the action felt... The catch is that this basically means that: it's a crime whenever it's convenient for the victim. In some cases even just whenever it's convenient for a lawyer that happens to come by. Where there's money to be sued out, there's a crime. I think the question we should ask is if such actions is detrimental to the list. Does it turn away people who are asking questions who may some day answer someone else's questions? Does it turn away people who maybe are newbies, but years later could be great Perl programmers if it weren't for one or two people stepping on them. Instead, they ended up being great Python/Ruby programmers...which would be good for these languages, though... The people that are likely to ever give anything back to the community are much less likely to receive harsh treatment, than those that mistake the list for a free script writing service. Of course those that are starting to give advice on the list run the risk of having their advice dissected and in some cases corrected. And then there are three kinds of people. Those that take that as an oportunity to learn, those that misunderstand the critique and take it personally and those that take that as an oportunity to feel offended. The first kind will learn, the second will eventually learn as well ... and the last ... would do better to complain somewhere they can actually extort some money. Shame is the last kind tends to start a flamewar even if it was not their code being criticized. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Real Beginner
From: Tiago Hori tiago.h...@gmail.com Hey Guys, I am a real beginner so at the risk of being slammed by some, I wanted to get some input. Don't worry, there are people here that will protect you and shout you were slammed even if you do not feel hurt at all. 5. [10] Modify the previous program to tell each new person the names of all of the people it has previously greeted: If you did not insist on the and between the last and one but last you could just use the join() builtin: print I've seen , join( , , @people), \n; if you do want the and, you need to do something more. Accessing the last element of an array is easy. It's either $people[ $#people ] or $people[ -1 ]. (Yes, you can index from the end with -1 being the last element, -2 the one before, etc.) To access all except the last you need to use something called array slice. If you use @ instead of $ in front of the variable name you may specify several indexes within the [ ] and get a list of array elements with those indexes. You can even use the range operator .. to specif a range of indexes. So all element except the last element would be @people[ 0 .. $#people-1 ]. You can then use the join() to put commas between the elements from first to the last-but-one and then add the and and the last element: print I've seen , join( , , @people[ 0 .. $#people-1]), and , $people[-1], \n; This will of course work correctly only if there are at least two elements in the @people array but testing that and printing the single element is easy :-) greet (Fred); Drop the ! In most cases it doesn't change a thing, but in some cases it can lead to hard to find bugs! If you do specify the parameters, then you've just bypassed the prototype on that subroutine (but there's hardly ever any so it doesn't matter much), but if you do not specify any parameters it will NOT call the subroutine with no parameters, but rather with the current parameters. See sub inner { print My parameters were: ', join(', ', @_), '\n } sub outer { inner(1, 2, 3); inner(); inner; inner(1, 2, 3); inner(); inner; } outer( Hello, world!); I am no perl expert, but this code looks really clunky to me, so I was just looking for some input. If your input is your code sucks without any constructive suggestion, please keep it for yourself, since I already know that my code sucks! :P I am beginner, that's what newbies do, they suck (in general, some people are brilliant and don't, not my case). Conversely to what some people make you believe you are very unlikely to be told your code sucks without being told why on this list. Jenda P.S.: Please use meaningfull subjects. Real Beginner doesn't say much. = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: devices without division
How to write a device funciton without using a '/' operator sub device_now($a, $b){ my ($a, $b)=@; don't use $result=$a/$b; return $result; } device_now(6,3); That's divide, not device. Not sure it's the solution that the professor had in mind, but you can use exponentiation (in Perl written as **, 5**2=25,5**3=125,...). It's enough to remember that x ** -1 = 1 / x and the rest is trivial. Another option would be to use a numerical solution. Guess the result, see whether it's too big or too small, change the guess accordingly, check again and continue like this until the error is small enough. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sample distribution
From: Peter Scott pe...@psdt.com On Tue, 19 Apr 2011 16:29:16 -0700, ai nguyen wrote: A population of 20 cows, each one has age and weight (known). Device this population into 2 group, each group has 10 cows. Questions: How to pick a cow on each group so that a distribution of AGE and WEIGHT on each group is similar. Show your strategy or/and implement it in PERL. Is this a question on a quiz or test you're taking? Do the people giving the test have the expectation that your answer is a measure of your abilities or those of people you've asked for help? How far have you gotten with a solution? Or if you're just posing a question as a challenge for people to exercise their brains, this would be better off in the Perl Quiz-of-the-Week list (which hasn't seen any traffic in aeons). Hey, dude! Beware of Fish! This was rude! You did not greet the nice person, you did not compliment his ability to copypaste his homework and you did not spoon-feed him. This way we'll scare off the beginners and we do not want to do that, right? Even if the beginners are lazy cheaters that believe their professor is not clever enough to check the archives and see who cheated. Jenda P.S.: Reading it again, it probably wasn't a copypaste job. Device ... = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Changing XML Tag Value in Perl
From: Rajpreet rajpreetsi...@gmail.com Thanks for your replies. But the above message is jst a sample and the exact message we get is pretty huge(its a trading sysem message)... I do have XML Parser installed.. I was trying to format a sample message using start and a default handler. I do get data in a variable and can change it, but how do I get the changed XML message in a new file. My question might be confusing or silly, but thats where I am currently stuck . I just wrote a dummy script- #!/usr/bin/perl use XML::Parser; Using XML::Parser directly is very seldom the right thing to do. Especially if you are just starting with Perl. See for example the filter mode of XML::Rules or have a look at XML::Twig. Both can handle huge XMLs without any problem. If used well. See the examples! Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Dynamic replacement of the variable
From: Shlomi Fish shlo...@iglu.org.il On Monday 18 Apr 2011 08:50:43 Uri Guttman wrote: SF == Shlomi Fish shlo...@iglu.org.il writes: SF Hi Uri, SF thanks for all your input on this list. See below for my response. SF On Monday 18 Apr 2011 07:56:16 Uri Guttman wrote: mr == marcos rebelo ole...@gmail.com writes: mr Ugly but may work, with a simple eval mr use strict; mr use warnings; mr my $var = '$str. q( abc_xyz)'; mr my $str; mr for(my $i=1;$i = 5; $i++){ mr $str = $i; mr my $line = 'Line: '.eval $var; mr print $line\n; mr } NEVER do that for such a simple problem. eval string is a last resort when no other technique can work well. SF Well, you are right naturally, but there is no need to be so SF rude. Start your email with a greeting, continue with a SF compliment, use soft words, etc. Otherwise, you may be scaring SF many people away. See some of my advice in: Try Alcoholics Anonymous. This is not a post-traumatic mutual support group, this is a technical mailing list! If you can't handle a terse and to the point reply, you should change the profession and try to find nicer talking people in the humanities. The catch is that the emails will start with a greeting, continue with a compliment, use soft words ... and be empty, empty, empty. You could have said that it is not a good thing, while being polite and much less hostile and angry. As it is, you are scaring many people from this list. As it is, those people should not be doing anything technical in the first place. The compiler will not start with a greeting and compliment their hairstyle either. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Dynamic replacement of the variable
From: Rob Dixon rob.di...@gmx.com On 19/04/2011 12:56, Jenda Krynicky wrote: SF Well, you are right naturally, but there is no need to be so SF rude. Start your email with a greeting, continue with a SF compliment, use soft words, etc. Otherwise, you may be scaring SF many people away. See some of my advice in: Try Alcoholics Anonymous. This is not a post-traumatic mutual support group, this is a technical mailing list! If you can't handle a terse and to the point reply, you should change the profession and try to find nicer talking people in the humanities. The catch is that the emails will start with a greeting, continue with a compliment, use soft words ... and be empty, empty, empty. You could have said that it is not a good thing, while being polite and much less hostile and angry. As it is, you are scaring many people from this list. As it is, those people should not be doing anything technical in the first place. The compiler will not start with a greeting and compliment their hairstyle either. You really believe that conveying technical knowledge requires rudeness, sarcasm, and snide remarks? No. But it doesn't require off topic compliments either. Programmers, especially the more experienced ones, tend to be busy folk. Both those that ask and those that reply. There was no rudeness in the original reply that caused all this weeping, much less sarcasm or snide remarks. It was a terse, to the point reply. Exactly what you should expect and get at a technical forum. Too many people here seem to think that the extent of their Perl knowledge entitles them to fits of bad manners and lazy language. If you struggle to make positive comments as well as negative ones then perhaps you should stick to writing Perl instead of trying to teach it. If there's nothing to positively comment on, I an't gonna make up something just so that someone would feel better. That's not what this list is for. If you need someone to pet your ego, find some other place for that. This is a place for technical questions! Nobody likes the pompous selfish drivers on the road that have more money than wit, and insist on driving their expensive cars badly and dangerously. They impress no one, and nor do those that are wealthy in knowledge but challenged in wisdom and common sense that like to post ridicule and abuse on this list. For goodness sake stop it and try to write well instead. I'd rather write the truth, than something that feels nice. From shawn wilson ag4ve...@gmail.com: well, it is our culture. some fields have a culture of inclusion, technology generally has a culture of exclusion. B U L L S H I T Technology generally has a culture of honesty. If you do something stupid, you are told you are doing something stupid. Without undue care about your ego, working under the asumption that you are a mature person. Yes, there are other fields where people treat you nice and kind ... letting you shot yourself in the foot rather than appering rude by telling you something you might not like to hear. From Alan Haggai Alavi alanhag...@alanhaggai.org: A mailing-list that welcomes new users and assists them is what I call a 'healthy mailing-list'. Such lists will increase user participation and eventually lead to the list being 'useful' to the posters as well as to the community. I see. So you think a greeting and made up compliments are assistance? Flaming is __HARM__ done to the community. No one enjoys it. It is the best way to be destructive! Which is exactly why we should cut off this silly thread. Especially since the very first to flame in this thread was Shlomi Fish! Let me quote again Uri's response: NEVER do that for such a simple problem. eval string is a last resort when no other technique can work well. and please learn to edit quoted email. there is no reason to see the whole original email. also read a full thread before answering is a good thing. this query was answered well several times already. Now that was incredibly rude. How could any human being write anything so insanely rude to another human being? Oh my gosh I'm gonna cryy Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: transposing %d values to %x output
From: Jim Gibson jimsgib...@gmail.com At 9:18 PM -0400 3/29/11, Chas. Owens wrote: It is important to note that \d doesn't match what you think it does. Starting with Perl 5.8, \d matches and digit character. This includes characters such as \x{1815} (Mongolian digit five). To match the ASCII digit characters you must use [0-9]: I have heard this advice before, and it just sounds silly to me. I deal exclusively with ASCII characters, so \d will only match the characters '0' through '9'. If any UTF characters have crept into my data unknowingly, then I have a bigger problem than too many matches. If I am dealing with Monogolian characters or with any other set of UTC characters, then I certainly want \d to match them as well. There is a good reason why the set of characters matched by \d was expanded. The \d had been rendered useless. \d had meant something I can do math with for too long to be changed to something someone might consider a digit. Which if it was to be correct would include the roman numerals I, V, X, L, C, D, M, ... Hey, it doesn't, \d is wrong even according to the silly new definition! The anything that might be considered a digit in Unicode they should have used some \N{} or \p{} and leave the \d alone. Yes, if you happened to want to match the mongolian digit thirteen you would have to use \p{IsDigit} or something. Huge deal. Instead of forcing those few and far apart that need (for whatever reason that completely alludes me) to match anything resembling a digit to use the Unicode \p{} construct or something similar, everyone had been forced to change their code to prevent their regexps suddenly matching something they never meant to match and that the computer will have no use for. So much for backwards compatibility. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Garbled lines
From: HACKER Nora nora.hac...@stgkk.at I am not sure whether this is really a Perl problem but maybe anybody can point me into the right direction: I am generating insert statements and writing them into a file for later execution. Most of the lines are written correctly: snipped Obviously, two insert statements get mixed and characters from both statements are written alternately. But how does this happen? Is this a Perl problem or could this be a buffer problem on the AIX server? Thanks for any hints! There are several instances of the script running at the same time writing into the same file? It would be better to give each instance its own file and then (if necessary) merge the files. Otherwise you'd have to use some IPC tools (semaphores or something) to control access to the file and flush the buffers correcrly to prevent such problems. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to avoid Out of Memory Errors when dealing with a large XML file?
From: Saqib Ali saqib.ali...@gmail.com I'm reading a large (57 MB) XML file Using XML::XPath::XMLParser() I keep getting this error: Callback called exit at XML/XPath/Node/Element.pm at line 144 during global destruction. I'm using Windows XP. So I watched the task-management memory meter during the execution of this process. The PERL process chewed up a lot of the available memory. But when the process died, it still showed about 216MB available memory. Is there anything I can do to work-around this problem? From reading responses to other similar questions, the only option may be to use a XML stream parser instead of one that builds the entire DOM tree internally. It might be best to switch to XML::Twig instead. It should be a simpler change than to go stream based. XML::Twig allows you to read the file in chunks giving you the tree for part of the XML. Hard to say without knowing the XML and what you need to do with it. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: [OT] The Happy, Happy, Feel Good Thread (WAS: New Document: How to Start Contributing to or Using Open Source Software)
From: Octavian Rasnita orasn...@gmail.com This answer is very good for Top posts don't bother me as much as those who don't trim the quotes. also. :-) When top-posting, the advantage is that it is not important how many messages remain at the bottom, exactly because nobody reads what's below the current message anyway. :-) Exactly ... if ... and it's a big if ... they still remember the old post. Which is something you may fairly safely assume in personal conversation but not on a mailing list. Expecially since most of the people most likely to be able to help are on several lists at the same time. And by the way, there was a period when it was OK to say words like black but now it isn't. And it was a much better period. Fuck newspeak and fuck political correctness. Rose, the same as shit, under any other name would smell the same. Change the smell, not the name! Otherwise you may go on changing the name every twenty years. There was a period when it was OK to follow that old netiquette that said that bottom-posting is the good way, but now it isn't. Because you said so? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: [OT] The Happy, Happy, Feel Good Thread (WAS: New Document: How to Start Contributing to or Using Open Source Software)
From: Octavian Rasnita orasn...@gmail.com From: Jenda Krynicky je...@krynicky.cz There was a period when it was OK to follow that old netiquette that said that bottom-posting is the good way, but now it isn't. Because you said so? Yes. Me and many others. I bottom post (on Perl - related mailing lists) and also usually trim the old posts, but not because bottom-post is the right way for Windows users - for most computer users, but because this is the preference of many Perl experts on these lists and it is a form of respect for their efforts, not for their opinions regarding the political corectness. They are not Windows, Mac or Unix users. They are mailing list users! And their OS has nothing to do with what's right for mailing lists. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML Challenge Cannot
From: Chaitanya Yanamadala dr.virus.in...@gmail.com Hai Liam Thank you for the reply. Thank u for letting me know an alternative for this. But there is a problem with what you have sent. It is not just removing of the bottom group tag that is required. If you check the input then u can find out that the title Commentary has 3 sub tags Letters, Books et al. and Policy Forum and under the tag Policy Forum u can find one more sub tag Policy Forum1 like this it can continue. what ever output which u have given will not give me the exact format of output that is required. 1. Learn to spell. 2. Learn to describe your questions in the necessary detail. 3. This is not a free script writing service. Even if you did succeed in describing the required output properly what makes you think we are going to waste time writing the script for you for free? Hire a programmer! Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Strategy for diagnosing context-sensitive bug
From: Rob Dixon rob.di...@gmx.com On 07/12/2010 09:24, Jonathan Pool wrote: The current script where the error occurs is at http://panlex.svn.sourceforge.net/viewvc/panlex/perl/plxu.cgi?revision=27view=markup The error occurs at line 1297. So the line in question is @res = (split /\n\n/, ($in{res} = (NmlML ($in{res}))), -1); and, although I can see no proper reason why it should make any difference in this case, I recommend removing the ampersand from the function call: it is bad practice in anything but very old Perl. I would also prefer to lose a few parentheses, purely for the sake of readability. So please try this: @res = split(/\n\n/, $in{res} = NmlML($in{res}), -1); I'd also suggest splitting this line in two. I feel uneasy about an assignment to a variable that was used to compute the assigned value somewhere in the middle of a parameter list ... $in{res} = NmlML($in{res}); @res = split(/\n\n/, $in{res}, -1); Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Object introspection + adding method
From: Jeff Peng pen...@nsbeta.info On Sat, Oct 23, 2010 at 07:52:50PM +0200, Shlomi Fish wrote: Just be sure you know what you are doing. Adding a method to somone else's class can be considered rude. See the NOTE in perldoc perlmodlib. He/she is maybe coming from other language like Ruby. In ruby it's free to add methods to any class including the built-in ones. Nothing prevents you from doing that in Perl either (well, with inside-out classes you'll have problems accessing the fields, but that's a different problem). The thing is that if you overdo this you end up with messy code. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl obfuscator
From: Shawn H Corey shawnhco...@gmail.com On 10-08-20 03:46 PM, Tobias Eichner wrote: Why do you need any obfuscator? If you want to protect your code from web access, put it in a module in a directory that cannot be access from the web and put a stub that calls the module at the site. It's not as easy as this, since people receive the source code files. No, they don't. The code is executed on the web server. They don't have access to the code at all. Not everything is web Shawn. The fact that if you run your code on your server (and set things right) the visitors of your website do not see the code is nice ... but irrelevant. If you are writing some code for a client and then give the code to the client to run on HIS computers then the client can see the code. And there's nothing you can do about it. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: A problem while using XML::Parser::PerlSAX
From: Jason Feng q15...@hotmail.com I am using XML::Parser::PerlSAX to parse a 300M XML file. I meet a strange issue with handler characters. This handler is supposed to return all the contents between start markup and end markup. But sometimes it just returns one part of the whole contents. On the second call, perhaps it returns the rest part of the contents. That is to be expected. From the docs of XML::Parser: Char (Expat, String) This event is generated when non-markup is recognized. The non-markup sequence of characters is in String. A single non-markup sequence of characters may generate multiple calls to this handler. Whatever the encoding of the string in the original document, this is given to the handler in UTF-8. Write your code so that it handles this. Or use a module that does this for you. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to allocation a desired size (e.g. 64KB) of contigugous memory block in perl?
From: Shlomi Fish shlo...@iglu.org.il On Wednesday 30 Jun 2010 10:01:45 Yang Zhou wrote: Hi Shlomi, Thanks for your help. I tried the my $buffer = \0 x 65536; method, but segmentation fault in the C function remains. I know little about XS, it seems a declaration of the interface between Perl and C? Just a glimps of the link in your last mail, I can't find any Keyword which can be used to solve this problem. You need to allocate a buffer for that in your C code using malloc() pass it to the function and then convert it to something that Perl can understand. Not necessarily, it is possible to preallocate in Perl and then use that buffer. Please show us your code, preferably trimmed down and let's see. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Simple, synchronous interaction with a local server process
From: Chap Harrison c...@pobox.com On Jun 26, 2010, at 7:34 AM, Jenda Krynicky wrote: Did you try DBD::ODBC? I do believe there are still ODBC drivers for dBaseIV installed on your computer so this should work. What problems did not you have? I *think* the problem is that dBaseIV drivers cost money. The company that I work for does have a license for the JDBC module, which is why I'm using that. I can't recall the problems I had a year or so ago, looking for an open-source (or at least free-as-in-beer) solution - seems to me I found some Version 1.0 drivers that didn't really install. Or something. You're right, DBD::ODBC would be by far the simplest approach, so I may see whether our license for JDBC also happens to include an ODBC module. dBaseIV drivers should install with ODBC on Windows. Within MDAC or whatever they call it. http://www.microsoft.com/downloads/details.aspx?displaylang=enFamilyI D=6c050fe3-c795-4b7d-b037-185d0506396c Getting some drivers that work under Unix would be a problem, but Windows should be fine. If you start the ODBC Manager (odbcad32.exe) do you see the Microsoft Access dBASE Driver? That's the one you need. It can handle dBase III, IV and 5.0. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML output processing question
From: saw saweinfi...@gmail.com Given one large XML file such as: A B CDE E=Eattr/F F=Fattr/G//D/C CDE E=Eattr/F F=Fattr/G//D/C !-- many more C sub-trees -- /B /A I want to create many small XML files consisting of a Root element and the C sub-tree. I would like to copy the C sub-tree from input to output as a block without having to address the sub-components. I have read the input into a hash using XML::Simple, but don't know how to copy the sub-tree which is also a hash. #!perl use strict; use warnings; no warnings 'uninitialized'; use XML::Rules; my $counter = 1; my $parser = XML::Rules-new( rules = { _default = 'raw', C = sub { my ($tag,$attrs,$parser) = @_[0,1,4]; my $file = sprintf results%06d.xml, $counter++; open my $OUT, '', $file or die Cannot create $file! $^E\n; print $OUT $parser-ToXML($tag,$attrs); close $OUT; return; } } ); $parser-parse(\*DATA); __DATA__ A B CDE E=Eattr/F F=Fattr/G//D/C CDE E=Eattr222/F F=Fattr/G//D/C !-- many more C sub-trees -- /B /A At most the contents of one C tag will be in the memory at a time. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Edit large data file
From: mrwawa wade.w...@gmail.com On Jun 16, 7:14 am, rwci...@alum.calberkeley.org (Robert Citek) wrote: On Tue, Jun 15, 2010 at 1:50 PM, mrwawa wade.w...@gmail.com wrote: Is this possible, and if so how can I do it? Can you give an example? For example, using colons instead of tabs, if the input looks like this: A:BC:D then you want it to look like this: A:B:C:D Is that right? Regards, - Robert That is correct. I decided to just write the output to a separate file and then delete the original file. Thanks for all your help. Wade That's all you can do. If you just wanted to change a few characters you could open the file for readwrite (open my $IN, '+', $file or ...), but since you need to insert characters you have to create a new file and copy the data, you can't expect the system to magicaly shift the data after the row you amended. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: What is the best way to parse a GPX (XML) file
Date sent: Wed, 16 Jun 2010 20:26:53 +0800 Subject:Re: What is the best way to parse a GPX (XML) file From: Jeff Pang jeffp...@aol.com To: robert Key robert...@telkomsa.net Copies to: beginners@perl.org 2010/6/16 robert Key robert...@telkomsa.net: Hi I would like to parse GPX file (XML) and insert certain data items into a MySQL database. There are mulitude of XML modules which can be used. These modules all build a hash from the data. Is this done because it is easy to find the the data simply using the key? I don't mind writing my own parser although this seems to be reinventing the wheel but some like XML::Parser are very general purpose and require a huge learning curve. How about XML::Simple? That's easy to learn and use. http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm XML::Simple has its quirks and problems. (I'm offline as I'm writing this.) Please search Simpler than XML::Simple on perlmonks.org for discussion of some and an alternative (almost drop in, but extendable). Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Simple, synchronous interaction with a local server process
From: Chap Harrison c...@pobox.com I have a Perl app that makes SQL queries to DBF (DBase IV) databases. I haven't found a reliable DBI::DBD module for accessing DBase IV, but I do have a copy of the JDBC library, so I wrote a simple Java command-line program that accepts a database path and a query on the command line, connects to the database, executes the query, and writes the result set to STDOUT. ... Did you try DBD::ODBC? I do believe there are still ODBC drivers for dBaseIV installed on your computer so this should work. What problems did not you have? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Here Docs
From: Uri Guttman u...@stemsystems.com JK == Jenda Krynicky je...@krynicky.cz writes: JK From: Joseph L. Casale jcas...@activenetwerx.com Inside a here doc, how can I force an expression to be evaluated such as localtime: here docs are just a different form of string so any technique which works in quoted strings will work in here docs. basic here docs are double quoted so they will interpolate scalars and arrays. JK use Interpolation eval = 'eval'; JK print END; JK $eval{localtime time} JK Foo JK Bar JK END i would say to just use a temporary scalar variable. there is no shame in doing this and it is simpler than using the Interpolation module which is doing tied things and calling eval (which is dangerous). Tie() yes, eval no. Neither the fact I called the hash eval, nor that I told it to use the builtin interpolation named eval means there is a string eval involved. See the docs online, there are quite a few more builtins and you can create your own interpolation. Eg. for formatting: use Interpolation d = 'commify'; my $total = 54858*745; print END; blah blah blah $d{$total} blah blah END Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Here Docs
From: Joseph L. Casale jcas...@activenetwerx.com Inside a here doc, how can I force an expression to be evaluated such as localtime: print END; `localtime time` Foo Bar END use Interpolation eval = 'eval'; print END; $eval{localtime time} Foo Bar END CPAN - http://search.cpan.org/ Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: get acl's of directory
From: Andreas Moroder andreas.moro...@sb-brixen.it Hello, is it possible to get the acl entrie of a directory on linux with perl ? Thanks Andreas What do you mean by acl? Access Control List? There is no such thing under Linux, the permissions system works differently there. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to create DSN on Solaris for Win32::ODBC
From: Parag Kalra paragka...@gmail.com Date sent: Thu, 8 Apr 2010 22:34:21 -0700 Subject:How to create DSN on Solaris for Win32::ODBC To: Perl Beginners beginners@perl.org Hi All, I am planing to use Win32::ODBC to connect to SQL Server from Solaris through Perl. You can't. Win32::ODBC only works under Windows. Besides you should use DBI in new scripts. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: [Was XS linker]
From: Rene Schickbauer rene.schickba...@gmail.com Some of the rules doesn't even make sense anymore, like the four-line-signature: Most people - when using their company mail account - are forced by local law to include a number of information (address, telephone number, company chairman, commercial registration number and so on). At least in some EU countries, the law also requires that this information is structured in a way so one can quickly find the correct bits of info. Which doesn't mean the rule doesn't make sense. It just means that sometimes it's hard or even impossible to comply. The rule should still be followed as much as possible. Many of us can't deal with the changes that happen in the past decade, either because we are old or because we are perfectionist, or both. I used to be one of those people, but i have grown up. Grown up or grown tired? In my opinion, people who bash other people for not writing Emails according to some outdated rules should be kicked in the seating module. Only after the people that can't spend a few minutes folowing the rules and thus making their posts easier to read and respond to. It may be impossible to prevent the addition of a company signature, but it's not impossible to remove the old signatures and other cruft. Jenda == je...@krynicky.cz == http://Jenda.Krynicky.cz == : What do people think? What, do people think? :-) -- Larry Wall in 199808071736.kaa12...@wall.org -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how do I replace all the spaces in a string with +
From: Erik Lewis ele...@ngrl.org snipped print Enter your address\n; chomp (my $rawaddress = ); my $geoaddress = $rawaddress =~ s/ /\+/; #strip the spaces from the address my $googlekey = ABQIJKeZa28YtErALcrbEC0UlBREf5oWR6F07BQvSEe3pww8R4s0VhTfTt-19vTI9qA-_V1pUf4-_TcfpQ; #get your google http://code.google.com/apis/maps/signup.html my $geocode_csv = get(http://maps.google.com/maps/geo?q=$geoaddressoutput=csvsensor=falsekey=$googlekey;) or die 'Unable to get page'; snipped As if I did not think so. No you do not need to replace spaces by plus signs! You need to escape the string for inclusion in a query string! use CGI::Enurl qw(enurl); my $geoaddress = enurl($rawaddress); or use URI::Escape qw(uri_escape); my $geoaddress = uri_escape($rawaddress); Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how do I replace all the spaces in a string with +
From: Erik Lewis ele...@ngrl.org Thanks that probably explains my higher than expected ungeocoded rate. Two weeks of playing with perl and I feel like I know less than when I started. The more you learn the more you find out you know nothing ;-) This feeling is to be expected. Don't let it overwhelm you and go on playing :-) And while we are at it ... Because they are all backwards! Why is that? Because it makes the posts hard to read. Why? Please do not top-post! Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML::Simple parsing with attributes
From: Shlomi Fish shlo...@iglu.org.il On Friday 22 Jan 2010 00:44:39 Jenda Krynicky wrote: From: Shlomi Fish shlo...@iglu.org.il This because you can very well represent XML in Perl data structures without any loss of complexity. See for example XML::Compile. Wrong! If for example you have something like {{{ pHello this is a a href=http://www.example.tld/;link for something/a/p }}}, then XML-Simple will make a mess out of it. And XML-Simple tends to break more often than not, and is philosopically unsound. Lovely. So you just found a type of XMLs that is and never was meant to be handled by XML::Simple and no one would ever suggest using XML::Simple for. Yes, and that is what XML is best for. Besides that, XML::Simple often puts arrays where there should be hashes, hashes where there should be arrays and tends to break more often than not. Marking up a document? Well, in some cases good enough for, yes. And whether should depends. Besides Dr. Ruud talked about XML::Compile, not XML::Simple in that sentence. Fine. XML::Compile seems to be for SOAP, which is a subset of the general XML functionality. I don't think it's only for SOAP. Besides even if it was, a specialised tool is most often best. You can cut and screw and saw and uncork and ... with your swiss army knife, but will it be more convenient than using a big knife, a real screwdriver, a real saw, ... hardly. XML::LibXML is overdesigned overcomplicated horribly documented comitee-designed thing. But everyone to his or her own tastes. You're missing many commas in this sentence of yours and a trailing and. I don't think I do. Is that a hard and black rock or a hard black rock? I disagree about it being either over-designed, over-complicated and committee (not comitee)-designed, aarenttllyy I did not double enough lettterrs. (Bloody english speaking people, what they write doesn't resemble what they read and vice versa and they do not know when to stop uselessly repeating letters.) because it is very elegant, powerful and flexible. It may not be very well-documented, but I could manage with the current state of its documentation. And it mirrors the current state of XML standards Which, if you ask me, is a drawback. I've tried to read the XML standards and the standards of a few more hyped xwhatever things. Bleargh. Overcomplicated. Pompous. Indigestible. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML::Simple parsing with attributes
Date sent: Fri, 15 Jan 2010 11:11:55 -0800 Subject:XML::Simple parsing with attributes From: Grant emailgr...@gmail.com To: Perl Beginners List beginners@perl.org Anybody here familiar with XML::Simple? I need to parse some XML that looks like this: LabelResponse Label Image Number=1base64datahere/Image Image Number=2base64datahere/Image Image Number=3base64datahere/Image /Label /LabelResponse I need to be able to grab the correct set of base64 data. Does anyone know how to do that? See http://www.perlmonks.org/?node_id=697036 You can either parse the whole file getting a consistent data structure or you can process the tags/twigs you are interested in as you go. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML::Simple parsing with attributes
From: Shlomi Fish shlo...@iglu.org.il This because you can very well represent XML in Perl data structures without any loss of complexity. See for example XML::Compile. Wrong! If for example you have something like {{{ pHello this is a a href=http://www.example.tld/;link for something/a/p }}}, then XML-Simple will make a mess out of it. And XML-Simple tends to break more often than not, and is philosopically unsound. Lovely. So you just found a type of XMLs that is and never was meant to be handled by XML::Simple and no one would ever suggest using XML::Simple for. Besides Dr. Ruud talked about XML::Compile, not XML::Simple in that sentence. Double-yuck. I still don't understand why you dislike me having quoting-designators. 'cause they are horribly overdone. It's like finishing sentences by ten exclamation marks XML::LibXML is overdesigned overcomplicated horribly documented comitee-designed thing. But everyone to his or her own tastes. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: What interative perl shell I should use to debug the perl code?
From: Peng Yu pengyu...@gmail.com It seems that there are more than one choices of perl interactive shells. I'm wondering which one is best or most popular. For example, I have a perl file that first load a huge data file then do some processing on the data file. The loading time is much longer than the processing time. If I can not run the perl file interactively, I will have to load the data file each time I run the processing code. However, I can interatively run perl code, I can load the data file once and run the processing code multiple times in order to debug the processing code. Apart from the perl debugger (that can be entered from within the script by this (strange looking) statement: $DB::single=2; there's also a PSH (Perl SHell) on CPAN and another unrelated PSH on http://Jenda.Krynicky.cz Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Clone an object
- You might, but what about others? You do want others to read your messages and help you with your questions, don't you? - But I remember what I wrote last time so I don't have to read it. - 'cause it's all backwards! - Why is that? - Because it's hard to read. - Why? - Please do not top post. From: Christoph Friedrich christ...@christophfriedrich.de My Big Problem is that I must copy an object to do a backtracking method (I am going to develop a sudoku solver). Not everything has to be an object. In either case the object must know how to clone itself. And how does it do that depends on its internals, on the way it stored its data. So do you need to copy a hash of scalars? An array? ... Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Clone an object
From: Erez Schatz moonb...@gmail.com Shlomi, please stop correcting the English of those who post here. It's rude, nope off-topic, maybe and unimportant. Not at all. Being able to express your needs/questions clearly is quite important. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Comparison of the comma versus the period in print statements
From: Marc Perry marcperrys...@gmail.com I noticed that most beginner texts will introduce and use print like this: print $moose, $squirrel, $boris, \n; However, when I review code from CPAN, I often (typically) see: print $bullwinkle . $rocky . $natasha . \n; As I recall, print is a list operator (and therefore the comma syntax is used to separate items in a list), but is catenation somehow faster/more memory efficient? Compared with the price of the IO operation the concatenation versus passing several values is irrelevant. I do not dare to guess which one is more efficient in what circumstances, but I don't think the difference matters. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: XML::Simple question
From: Mike Blezien mick...@frontiernet.net Hello, were using the XML/Simple module to process a XML response using the code below. But for some reason the module can't read the $xmlresponse data unless we create a temp file first to store the data then pass that to the module. Is there a way to do this without having to create a temp file first. ?? Everything does work, the response is return. We used the Data/Dumper module to verify the data first. = my $ua = new LWP::UserAgent; $ua-timeout(10); $ua-agent(HTTP/1.1); my $req = new HTTP::Request 'POST' = $xmlscript; DO NOT QUOTE VARIABLES! If the $variable already contains a string, you just unnecessary make a copy. If it contains a number (well it can contain both, but I mean the case when it contains just the number), you force Perl to convert the number to string (and store that string alongside the number in the variable) and make a copy of the string. And possibly later it will have to convert the string back to number. And these are the cases when it actually works, even if it's inefficient. As soon as you quote like this a variable that contains a reference or an object (a reference bless()ed to a package), you end up with useles string, that will just look like a reference when printed out. Do not quote variables! my $req = new HTTP::Request 'POST' = $xmlscript; is enough! my $simple = new XML::Simple(KeyAttr=[]); # read XML file my $xmldata = $simple-XMLin($xmlresponse); OK, you are safe from automatic key related transformations ... what about tags with optional attributes? Or tags that are sometimes but not always repeated? See http://www.perlmonks.org/?node_id=697036 Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: what's a database handler
From: Xiao Lan (a°a...°) practicalp...@gmail.com Hi, When I get a database handler with DBI, my $dbh = DBI-connect(...); That's a handle not a handler. A very different thing. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: capture error - the better way?
From: Philip Potter philip.g.pot...@gmail.com 2009/12/16 Shlomi Fish shlo...@iglu.org.il: On Tuesday 15 Dec 2009 17:14:25 Philip Potter wrote: If evaluating a constant expression results in a runtime exception, that runtime exception must happen at runtime, and not at compile time. In general, it is the duty of an optimizer never to change program behaviour, only performance. But this is a case where the compiler evaluates a constant expression and it results in an exception. So it cannot store it as a folded constant on the side for the run-time place. As a result, it throws a compile-time error. Yes, it can't fold the constant. That's no excuse for changing the behaviour of the program. What it should do is what I wrote in my previous email -- replace it with code that raises a runtime exception when executed -- ie a die Illegal division by zero. An exception that get's raised every time is not very ... exceptional. What it should do is what it did. Tell you you are doing something stupid. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help me understand
From: 120 zen158...@zen.co.uk I've looked at this: sub encrypt { my $self = shift; my $xx = $$self; #.. cut stuff I do understand return $self-SUPER::encrypt(); } Could someone help me with the Perl to English here? I get that $self is shifting the arguement. $self is set to the value of the first parameter of the subroutine encrypt(). In case the encrypt() was called as a method, it will be the object you called the method on $obj-encrypt() - $self = $obj; I think I get that $xx is a reference to $self? No. $self was a reference to a scalar, $xx = $$self puts the value of that scalar into $xx. I don't get at all: return $self-SUPER::encrypt(); Is this assigning the $self to the results of a call to a class called SUPER's method encrypt? No. This returns the result of calling the inherited version of the encrypt() method on the object. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: speed test
From: Rob Coops rco...@gmail.com A daily job that by the sound of it will not be changing a whole lot, jut get executed pretty much till the end of times... C is your friend. Perl would certainly get the job done and on time without to much problems, but if you are worried there isn't much that will out perform C/C++ when it comes to raw speed. If you are able to implement it well enough. Keep in mind that a lot of time was spent on optimizing the builtins and the regexp engine, much more time than you can spend on your program. So if the problem at hand matches well enough Perl strengths, your Perl solution may even be quicker than your C solution. Plus it's not one or the other, you can combine the two. You can write the program in Perl and if and only if you find out it's too slow you can benchmark it and write just the problematic parts in C. If you are not planning on making any changes to the code in the foreseeable future, the extra readability of the Perl code should not really mater as you do not expect to be making changes to it on a regular basis anyway. Expect the unexpected. And regular changes are not the problem. The problem are irregular, once in a while changes that have to be finished right now or if possible last week. My biggest worry would not be the 1T (of logs I guess) the code needs to parse now, but in 4 or 5 years from now the likely doubled amount of data. what was the name of that law? Something that said that the speed of computers doubles every ??? years. If in four or five years the data amount is only doubled, you are more than safe. And if it's parsing logs, then unless you intend to do some natural language processing, then IO will be the problem, not the CPU/language speed. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Assignment Operator
From: Marco Pacini i...@marcopacini.org Subject:Assignment Operator Date sent: Thu, 26 Nov 2009 12:31:54 +0100 To: beginners@perl.org Hi All, I'm studying Perl since one week on Learning Perl written by L. Wall and in the paragraph Assignment Operators i don't understand why this: ($temp = $global) += $constant; is equivalent of: $tmp = $global + $constant; I believe you meant $temp, not $tmp Instead, before i read it, i thought it was equivalent of: $temp = $global; $temp = $temp + $constant; You were right, though unless the $temp is a tie()d variable, they are all equivalent. If $temp is tie()d, then the first and third will call the STORE method twice abd FETCH once, while the second calls just STORE once. This may cause the result to be different if the STORE modifies the stored value. Eg. by rounding it. #!perl package TstTie; require Tie::Scalar; @ISA = qw(Tie::Scalar); sub FETCH { print FETCH ${$_[0]}\n; return ${$_[0]} } sub STORE { print STORE $_[1]\n; ${$_[0]} = $_[1] } sub TIESCALAR { my ($class, $value) = @_; return bless( \$value, $class)} package main; my $temp=4; tie $temp, 'TstTie', 4; my $global = 10; my $constant = 7; print Original:\n; ($temp = $global) += $constant; print Result: $temp\n\n; print First:\n; $temp = $global + $constant; print Result: $temp\n\n; print Second:\n; $temp = $global; $temp = $temp + $constant; print Result: $temp\n\n; __END__ (Keep in mind that the print Result: $temp\n\n; causes on more FETCH! Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: 答复: the question of one program
From: Philip Potter philip.g.pot...@gmail.com 2009/11/20 gaochong zjgaoch...@gmail.com: Thanks . But the code is from cpan.org ,and is crappy ,where I will go ? CPAN has no quality control. There is no guarantee that anything you get from CPAN will not be, as you say, crappy. As a result, be selective with what you download from CPAN. Ask questions, go by reputation, check that the module is maintained (if it hasn't been updated since 2003, the owner clearly doesn't care about it much any more), Don't look at the last release date! Rather at the age of the oldest opened bug report in RT. The module may well be complete enough and bugfree enough that there is no need to release new versions. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Trace used functions within an app
From: Dermot paik...@googlemail.com I have been asked to look at/add features to an existing ModPerl app that has thousands of lines of code spread over tens of modules. Some are OO, some are function-oriented. There looks like there's lots of debris and unused functions. For clarity, simplicity and maintainability, I want to remove the stuff that is no longer used or needed. Is there any module/method that can help me trace what functions are being used? I could add a print statement to every function but that would take a while to do and then I'd have to parse the http logs to correlate the data. What I think I need is some independent module that sits at the top of the name-space and logs the functions to a separate log. Does anyone have any ideas that might help? Thanx, Dp. Looks to me like you are looking for a profiler. Have a loop at CPAN - http://search.cpan.org/ Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sorting mixed alphanumerics
Date sent: Wed, 14 Oct 2009 11:03:13 -0400 From: Shawn H Corey shawnhco...@gmail.com To: Rick Triplett r...@reason.net Copies to: Perl Beginners beginners@perl.org Subject:Re: Sorting mixed alphanumerics Rick Triplett wrote: I need to sort the keys in a hash. The keys are the question number and the values are the student's answer. A numeric sort with = won't work since retaking a missed question (say, 2) produces the new key, 2h with its new answer. A representative hash might look like this You need a Schwartzian transform. It works by extract the sort fields from the data and placing them, and the original data, in an array of arrays (AoA). It sorts the AoA and extracts the original data from them. This sorted list now can be used. ST is an overkill if the extraction is simple. Especially if the number of items is fairly small. Actually if the extraction is really simple and the extracted key is not so small, than ST may perform worse than an ordinary sort doing the extraction within the comparison block. The additional array creation and destruction and increased memory load will more than ofset the lower number of extractions. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sorting mixed alphanumerics
From: Shawn H Corey shawnhco...@gmail.com Jenda Krynicky wrote: ST is an overkill if the extraction is simple. Especially if the number of items is fairly small. Actually if the extraction is really simple and the extracted key is not so small, than ST may perform worse than an ordinary sort doing the extraction within the comparison block. The additional array creation and destruction and increased memory load will more than ofset the lower number of extractions. Who cares? Modern computers are big enough and fast enough to handle everything except editing movies. OK. So because modern computers are fast enough to handle everything you'll employ an optimization pattern that actually hurts performance even though it complicates the code. Lovely. Using ST while it's not needed is silly. Pattern or no pattern. In this particular case the best solution is to silence the bogus warning. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: DBI driving me nuts ... !
Please can you advise ? #!/usr/bin/perl use Mysql; $dbh = Mysql-connect(localhost,mailscanner,root,c0nc3pt) or die (Error . Mysql-errno . - . Mysql-errstr); ... I do not see any DBI in here. Though ... http://search.cpan.org/~capttofu/DBD-mysql- 3.0008/lib/Mysql.pm says M(y)sqlPerl is no longer a separate module. Instead it is emulated using the DBI drivers. You are strongly encouraged to implement new code with DBI directly. ... In either case you put the data for the row into @row and then attempt to print $row. Those are two different variables. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Arrays, Dates, Indexing and Initialisation
Date sent: Mon, 28 Sep 2009 09:11:02 -0700 Subject:Re: Arrays, Dates, Indexing and Initialisation From: r...@i.frys.com To: Soham Das soham...@yahoo.co.in Copies to: beginners@perl.org Soham Das wrote: Hello All, I wanted some guidance with these questions of mine: a.. How do I initialise an array of a definite size with zero. Say the C equivalent of such a statement will be: int a[125]; for(i=0;i125;i++) a[i]=0; my @array; $array[$_] = 0 for 0..125; my @array = (0) x 126; Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: typical errors beginners make
From: Gabor Szabo szab...@gmail.com For some reason - maybe because my students are not English speakers - many of them type use warning; Which gives them the following error: Can't locate warning.pm in @INC (@INC contains: /home/gabor/perl5lib/lib/perl5/site_perl/5.10.0/i486-linux-gnu-thread-multi ... You do not have to explain @INC right away. Can't locate warning.pm sounds clear enough to me. You tell them Perl libraries/modules have the .pm extension and that this message meant that they either mistyped the module name or that it's not installed. No need to dive into more details. I think the message would be even better without the in @INC, but that doesn't matter much. The fact that @INC holds the list of library directories is apparent. IMHO if you want to give better explanations, post patches to perldiag and add use diagnostics; to the beginner mode programs. And to find the other possibly problematic code constructs I think you'd better use Perl::Critic with whatever settings you think are best for beginners than attempting to develop your own. I do believe most of the confusing things are already covered. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: text html from file to a scalar and mail
From: Shlomi Fish shlo...@iglu.org.il use FileHandle; my $signature = new FileHandle; $signature-open($signature_file)or die Could not open file\n; You should use IO::Handle instead of File::Handle (or IO::File in your case), and use the three args open. It's nice you've used die. Nope. You should not be bothering with thatever class is at the moment behind the Perl filehandles and just use open() as a function. Not everything has to be an object open my $SIGNATURE, '', $signature_file or die Could not open '$signature_file': $^E\n; $signature is not a good name for a filehandle - better call it $signature_fh. I use all capitals for filehandles. Both oldstyle and lexical. my $fileHandle = $_[0]; Accessing $_[$idx] is not very robust - you should do: my $fileHandle = shift; Or: my ($fileHandle) = @_; Nope. Accessing $_[$idx] all over the place within the subroutine would be prone to errors and inconvenient (though sometimes necessary), what syntax do you use to copy the parameters into lexical variables is largely unimportant. And sometimes you can't just shift() off parameters from @_, you need to keep them there. my $customer_msg_html = $customer_msgStart_html . OrderFromForm_html() . $customer_msgEnd_html . $scalar_sig; Your style is inconsistent between camelCase, and underscore_separated_identifiers. Maybe there is a meaning to the underscores on some places and case change in others. Don't be so quick. The fact that you do not see a pattern from a very short example doesn't necessarily mean there isn't one. It may very well be too big to fit in the small cut hole that you see. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: watch folder concept in Perl
Date sent: Mon, 7 Sep 2009 17:58:35 +0530 Subject:watch folder concept in Perl From: Ganesh Babu N nbabugan...@gmail.com To: Perl beginners@perl.org Dear All, Can we develop application which will watch a specific folder and when any files comes into the folder then some action takes place in Perl. Similar to an windows service. Is it possible in Perl. Regards, Ganesh There are several libraries for this. For Windows have a look at Win32::ChangeNotify and Win32::IPC. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: search replace saved to a variable
From: Noah Garrett Wallach noah-l...@enabled.com okay a step further - is there a way to make the following a one liner? (my $filename_cmd = $cmd[-1]) =~ s/\|//g; $filename_cmd =~ s/\s+/\./g; $filename_cmd =~ s/save.*//g; There's no point in making it a one liner. Plus anything may be writen as a oneliner in Perl ... it would just be a long line in some cases. In this case I'd write this as: my $filename_cmd = $cmd[-1]; for ($filename_cmd) { s/\|//g; s/\s+/\./g; s/save.*//g; } Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl's superior text parsing power
From: Shawn H. Corey shawnhco...@gmail.com Dave Tang wrote: I wanted to ask why is Perl, in comparison to other programming languages, so powerful in text processing? Undoubtedly, when it was written, Perl was the most powerful text processing language available. This is no longer the case (thanks largely to Perl :). Today's scripting languages have the same text processing abilities as Perl. Some of them do have the same basic functionality. None of them has such a huge archive of ready-to-use libraries for all kinds of (not only) text processing. Sure you can write the same libraries in the other langauges, but the problem is exactly that. You have to write them. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Creating array variable names on the fly
From: ANJAN PURKAYASTHA anjan.purkayas...@gmail.com Hi, I have a question on creating array variables. I have a driver script that takes as input the number of files to be processed (say 7). One of the children scripts needs to create array variables based on how many files are being processed (in this case 7). How do I code the following action into the child script: read the number of files to be processed. based on this number create a set of arrays say @array1, @array2@array7? You do not want to do that! Please read this http://perl.plover.com/varvarname.html and http://www.oreillynet.com/pub/a/network/2001/05/18/perl_redflags.html Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: removing a 'tee'd file handles going forward
Date sent: Wed, 26 Aug 2009 15:36:26 + (GMT) From: Tony Esposito tony1234567...@yahoo.co.uk Subject:removing a 'tee'd file handles going forward To: Beginners Perl beginners@perl.org I want to output to both STDOUT and STDERR at one point in my program, then want to separate the two handles going forward in the program so that output is sent to STDOUT and STDERR separately. Given the code snip below, would the undef tee do the trick? use IO::Tee; my $tee = new IO::Tee(\*STDOUT,\*STDERR); $tee-print(Hi\n); $tee-flush; # some code here ... blah, blah, blah ... # now want to change to set and 'untee' STDOUT and STDERR ... undef tee; # is this going to do it? Well it will, but there is no need to do that. You can print to STDOUT and STDERR even while the tee exists. print $tee Foo\n; will go to both print STDOUT Foo\n; will go to STDOUT and print STDERR Foo\n; to STDERR. And print Foo\n; to the select()ed filehandle. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: removing a 'tee'd file handles going forward
From: Tony Esposito tony1234567...@yahoo.co.uk Agreed. But the program flow would be such (pseudo-code): (1) print STDOUT print STDERR (2) now print to both in one print statement (3) now go back to print STDOUT print STDERR I want to switch back-and-forth between being able to print to STDOUT, STDERR with one 'print' statement and then back ... HTH I said you can! And you do not have to destroy the tee and then create it again. Once you create the tee you can print to STDOUT, STDERR or the teen any time you want, as many times you want and in any order you want. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Procedural modules in an object-oriented project
From: Steve Bertrand st...@ibctech.ca My ISP management project which started out as a learning experience has grown into a system that currently contains 10 modules. The entire system is object-oriented. While reviewing my POD to ensure that I've been keeping it up-to-date properly, and so that I can still easily understand the API at the documentation level, I've noticed that two of my modules have subroutines that only perform global tasks, and don't need to be object-oriented at all. Is it recommended that I stick with the overall style of the project by making all of the modules object-oriented, or is it better to create procedural modules when objects are not required? Depends. Not on the project or the code, but rather on the person you ask. If you ask me ... yes, it's perfectly fine to use OO only where it actually helps with something and plain old procedural interface where it doesn't. If you ask someone else, he/she may very well try to talk you into writing everything as objects and classes. Use whatever feels more natural to you. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Attentipn Please!! Need A Perl script to read the UIDs from two text files having the details in the format as given in th
From: Ian pcs...@gmail.com This is how I would do it. To every one else, please feel free to critique my perl programming skills. I'm a Mainframe Assembler programmer and still learning perl. Any critique will just help to improve my skills. The script is fine, the fact that you wrote it for free for someone who can't even ask nicely is not. I understand you want to practice, but sometimes the best reply is no reply. Any email that starts Attentipn Please!! Need A Perl script should be ignored. But at least Jyotishmaan Ray is spiritually enjoying himself. Spiritualy aware. Indiot. This is not a free scripting service! Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Coding best practices
From: Shawn H. Corey shawnhco...@gmail.com I use Data::Dumper a lot, so most of my debugging statements have Dumper in them, making them easy to find. For those that don't, I add # TEMPORARY at the end. And I leave them behind; I just put a # in front of them. :) I tend to not indent them. So they stick out and since pretty much all code is indented at least one level in any nontrivial program, I only have to look for /^print/. Whether I leave them behind or not depends on whether I expect to need them again. Usually I remove them after I'm done debugging. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- 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?
From: Philip Potter philip.g.pot...@gmail.com Dear all, I'm trying to learn to use the IO::File object as a means of passing a filehandle from one function to another. In the perldoc documentation for IO::File, it gives the example: undef $fh; # automatically closes the file but in the reference that follows, it gives no indication for why this might be the case. Would this behaviour be caused by the destructor? Yes If $fh goes out of scope, will the file be automatically closed? Yes And you do not have to go all OO to make use of this. open my $FH, '', $filename or die; creates such an object as well. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Inverting a hash safely
From: Ed Avis e...@waniasset.com My question is, does there exist a 'safe hash invert' function in some CPAN module? I was imagining something like my %hash = (a = 1, b = 2); my %reverse = safe_hash_invert %hash; # works fine $hash{c} = 1; %reverse = safe_hash_invert %hash; # throws an error 'duplicate values...' I see Hash::Util and Hash::MoreUtils on CPAN but neither provides such a function. Before I write one myself I wanted to check if there is already a standard implementation. I don't think there is and I don't think there's a need. my %hash = (a = 1, b = 2, c = 1, ); my %reverse = reverse %hash; die Bummer, the values were not unique! if keys(%hash) != keys(%reverse); Complex, was it? :-) As the test whether the values are unique would have to build a hash of the values, there's no point in testing first and then building the reverted hash. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: while () and wildcards on DOS/Windows
From: Peter Daum gator...@yahoo.de I occasionally have to write Perl scripts that should behave the same on Unix- and DOS-like Systems. One little problem I encounter there is: For quick hacks, the while() mechanism is very handy, because it saves a lot of typing. On Unix, I can call a script as a filter, with filenames or with glob-Patterns without having to worry about the details - in any case I can just use to read the data. On DOS (and its descendants), this used to be the same - I still have an old binary of Perl 5.005 lying around, where Perl silently takes over the glob expansion that on Unix would be done by the shell. Unfortunately, this obviously is not the case anymore: With more recent Perl versions, when a script is called with '*.xyz' it will just try to open '*.xyz' and fail. The only workaround I know is to do something like: ... snipped You might like http://jenda.krynicky.cz/#G Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Inverting a hash safely
From: Ed Avis e...@waniasset.com Jenda Krynicky Jenda at Krynicky.cz writes: my %hash = (a = 1, b = 2); my %reverse = safe_hash_invert %hash; # works fine $hash{c} = 1; %reverse = safe_hash_invert %hash; # throws an error I don't think there is and I don't think there's a need. my %hash = (a = 1, b = 2, c = 1, ); my %reverse = reverse %hash; die Bummer, the values were not unique! if keys(%hash) != keys(%reverse); Of course this works. But even at three lines of code it's still worth making into a function. The 'any' and 'none' functions in List::MoreUtils are even more trivial but it's still very handy to have them. To give a really useful error message is a bit more code: my %reverse; foreach my $k (sort keys %hash) { my $v = $hash{$k}; if (exists $reverse{$k}) { die cannot reverse: $v is mapped to by both $k and $reverse{$k}\n; } $reverse{$k} = $v; } And is this message useful? I mean, if you as the user of the program receive this message does it tell you anything useful? Will you know what hash was it? Maybe you can find out because the values remind you of something you saw for example in a config file, but maybe not. The function would only be of some use if you could specify the message. Otherwise you'd have to wrap it in an eval{}, catch it, make sure it's this message and rethrow the exception with a more informative text. And hope the next version of the module doesn't change the message. However, even if it's just one extra line of code as you suggest, that still makes it temptingly easy to just forget the check. I did so myself, and while I am no Don Knuth, I'm more conscientious than some people I know! So if I can forget to check it so can many others. You can't prevent people from shooting themselves into their feet. So one reason to have a function providing this is to give a simple FAQ entry on reversing a hash: 'just use Whatever::Module::safe_hash_invert'. And, for those who like that kind of thing, a simple way to audit existing code for bugs (or latent bugs) caused by hash reversing without checking; I would ideally provide both safe_hash_invert and unsafe_hash_invert so that the programmer can be explicit about what's intended. If anything, it would be better to provide a function that'd check whether the values of the hash are unique so that you could assert(values_are_unique \%hash); before the reverse(). Because you should only reverse hashes that by definition have unique values. So this is something you should test, but do not necessarily want to test each and every time in the release build. And if you feel like it, create a function that reverses (a = 1, b = 3, c = 1) = (1 = ['a','c'], 2 = ['b']) That's something that's not a SIMPLE oneliner. Even though of course it's not too complex either. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Inverting a hash safely
From: Shawn H. Corey shawnhco...@gmail.com Jenda Krynicky wrote: And if you feel like it, create a function that reverses (a = 1, b = 3, c = 1) = (1 = ['a','c'], 2 = ['b']) That's something that's not a SIMPLE oneliner. Even though of course it's not too complex either. I think it's simple enough: #!/usr/bin/perl use strict; use warnings; use Data::Dumper; # Make Data::Dumper pretty $Data::Dumper::Sortkeys = 1; # ASCII sort hash keys $Data::Dumper::Indent = 1; # first style, not indent 1 space $Data::Dumper::Maxdepth = 0; # limits depth of output, zero == infinite my %h = (a = 1, b = 3, c = 1); my %r = (); push @{ $r{$h{$_}} }, $_ for keys %h; # one line :) Is it simple enough so that you immediately know what does it do? I guess not. IMHO it's complex enough to warrant being moved to a named subroutine. Especially since it forces you to write the name of the original hash twice. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Need help with Mail::Sender
Date sent: Thu, 25 Jun 2009 23:27:24 -0500 From: Dennis Wicks dgwi...@gmail.com To: Perl Beginners beginners@perl.org Subject:Need help with Mail::Sender Greetings; Following the docs I have it working, somewhat, but it is not handling html w/inline images correctly. Instead of getting an html message with inline image it is sending a blank email with both the html and the jpg image as attachments. Here is my program. Does anyone see the problem? Yes, the problem is very simple. Each mail client handles this differently. What works in one, fails with the other. This is what worked for me in Pegasus Mail: #!perl use Mail::Sender; eval { (new Mail::Sender) -OpenMultipart({ to = 'je...@krynicky.cz,je...@operamail.com', subject = 'Embedded Image Test', boundary = 'boundary-test-1', type = 'multipart/related', smtp= 'xxx', auth = 'PLAIN', authid = 'xxx', authpwd = 'xxx', }) -Attach({ description = 'html body', ctype = 'text/html; charset=us-ascii', encoding = '7bit', disposition = 'NONE', file = 'c:\temp\zk.html' }) -Attach({ description = 'Test gif', ctype = 'image/gif', encoding = 'base64', disposition = inline; filename=\test.gif\;\r\nContent-ID: img1, file = 'D:\pix\humor\alc.jpg' }) -Close() } or die Cannot send mail: $Mail::Sender::Error\n; __END__ and the c:\temp\zk.html contained: html body phi again/p img src=cid:img1 pEnde/p /body /html If I send the email to my operamail account, the HTML is in the body, but the image doesn't display correctly. Try to change the headers or try to post a HTML email with images with your mail client and see what headers does that use. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: redirecting STDERR with IO::Tee
Date sent: Mon, 22 Jun 2009 10:53:06 -0700 From: pa...@compugenic.com To: beginners@perl.org Subject:redirecting STDERR with IO::Tee I have a script which runs mostly via a cron job and sometimes interactively. I would like STDERR to automatically print to both the console and to a logfile simultaneously. Right now I've gotten as far as merging both file handles with IO::Tee but I'm not sure if I'm heading down the right path. my $merged_stderr = IO::Tee-new( \*STDERR, new IO::File($errlog) ); This only works when explicitely naming the file handle in a print statement. How can I take it to the next step, which is to have STDERR automatically print to that file handle? #!perl use strict; use IO::Tee; warn Before the change; open my $oldSTDERR, 'STDERR' or die; close STDERR; open my $DBG, '', 'debug.log' or die; *STDERR = IO::Tee-new( $oldSTDERR, $DBG) or die; warn after the change; print to STDOUT\n; print STDERR to STDERR\n; system ('dir sdf_sgerdfwerg'); die Bleargh; __END__ it's not possible to tee (this way) the STDERR of the child processes, the best you can do is to decide whether you want them to go to the file or the ordinary error output. Try to escape the close STDERR;. HTH, Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question about constants
From: Roman Makurin dro...@gmail.com here is complite perl script which produces such results without any warning: #!/usr/bin/perl use strict; use warnings; use constant { A = 0, B = 1, C = 2 }; my @a = (A, B, C); my @b = (1, 2, 3); while(my $i = shift @a) { print $i, $/ } But of course this does not print anything. The shift(@a) returns the first element of @a which is zero, assigns that to $i and then checks whether it's true. And of course it's not. So it skips the body and leaves the loop. Keep in mind that the value of my $i = shift @a is NOT a true/false whether there was something shifted from the array. It's the value that was removed from the array and assigned to the $i. And if that value it false (undef, 0, 0.0, 0, 0.0, - if I remember rigth) then the whole expression evaluates to false in boolean context. Whether you use constants or not is irrelevant. You'd see the same behaviour with my @a = (0, 1, 2); HTH, Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question about constants
Steve Bertrand st...@ibctech.ca wrote: Roman Makurin wrote: On Wed, Jun 24, 2009 at 03:25:57PM +0200, Jenda Krynicky wrote: From: Roman Makurin dro...@gmail.com here is complite perl script which produces such results without any warning: #!/usr/bin/perl use strict; use warnings; use constant { A = 0, B = 1, C = 2 }; my @a = (A, B, C); my @b = (1, 2, 3); while(my $i = shift @a) { print $i, $/ } But of course this does not print anything. The shift(@a) returns the first element of @a which is zero, assigns that to $i and then checks whether it's true. And of course it's not. So it skips the body and leaves the loop. Keep in mind that the value of my $i = shift @a is NOT a true/false whether there was something shifted from the array. It's the value that was removed from the array and assigned to the $i. And if that value it false (undef, 0, 0.0, 0, 0.0, - if I remember rigth) then the whole expression evaluates to false in boolean context. If I understand correctly, what you are saying is that while() is evaluating the left side of the '=' as it's condition, culminating into: while($i) Which eventually equates into: while(0) ...on the very first pass. Well, you could understand it like that in this case. The problem comes as soon as the assignment is not a scalar, but rather a list one. Which doesn't mean just this my @foo = whatever(); but also my ($x, $y) = whatever(); and even my ($x) = whatever(); Because the scalar value of such an assignment is the number of assigned values, not the first or last such value. See print scalar(my $x = 'hello'),\n; print scalar(my ($x) = 'hello'),\n; print scalar(my ($x,$y) = 'hello'),\n; If you want to loop over a list and consume it by the loop you should use this: while (@array) { my $x = shift(@array); ... } Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question about eval usage
From: Roman Makurin dro...@gmail.com Just looked throught some standart perl modules and found something cryptic to myself: package Module; $Module::VERSION = '1.0'; $Module::VERSION = eval $Module::VERSION; Why eval part is needed here ? It's not. What module was that? Maybe you skipped something that was the reason. Jenda P.S.: Your English is fine. Just drop the -self. ... cryptic to me. I did it myself vs. It looks good to me. = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question about eval usage
From: Roman Makurin dro...@gmail.com On Tue, Jun 23, 2009 at 12:46:33PM +0200, Jenda Krynicky wrote: From: Roman Makurin dro...@gmail.com Just looked throught some standart perl modules and found something cryptic to myself: package Module; $Module::VERSION = '1.0'; $Module::VERSION = eval $Module::VERSION; Why eval part is needed here ? It's not. What module was that? Maybe you skipped something that was the reason. File::Spec and CPAN, maybe other Looks like cargo culting to me. Maybe someone let their source control system update the version string and needed the eval to turn it into something Perl understands. In this case you'd get the same result by $Module::VERSION = 0 + $Module::VERSION; because the only difference between the $VERSION before and after the line above or the eval is that before it's a string and after it's a number. But Perl happily converts that any time it's needed so it's irrelevant in all except very very few cases. I'm actually not so surprised it's in File::Spec. That's one heck of an inconveniently designed module. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: question about eval usage
From: Paul Johnson p...@pjcj.net On Tue, Jun 23, 2009 at 06:35:26PM +0200, Jenda Krynicky wrote: From: Roman Makurin dro...@gmail.com On Tue, Jun 23, 2009 at 12:46:33PM +0200, Jenda Krynicky wrote: From: Roman Makurin dro...@gmail.com Just looked throught some standart perl modules and found something cryptic to myself: package Module; $Module::VERSION = '1.0'; $Module::VERSION = eval $Module::VERSION; Why eval part is needed here ? It's not. What module was that? Maybe you skipped something that was the reason. File::Spec and CPAN, maybe other Looks like cargo culting to me. From the docs: http://perldoc.perl.org/perlmodstyle.html#Version-numbering Bleargh. Not that it doesn't work. In a way. But my that is ugly! If you want to remove underscores, do remove underscores! Do not eval the stuff! Unless it's part of a JAPH or OBFU. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Need help with Email::Send
From: Dennis G. Wicks dgwi...@gmail.com Jeff Pang wrote the following on 06/21/2009 09:51 PM: 2009/6/22 Dennis G. Wicks dgwi...@gmail.com: Greetings; I can't seem to find the problem with the Email::Send portion of this program. It may be that I am getting an error from the smtp server but I haven't been able to adapt an error routine that works with Mail::Sender to work with Email::Send. Why? What's wrong with Mail::Sender? I have seen these info on the module's page: Email::Send is going away... well, not really going away, but it's being officially marked out of favor. It has API design problems that make it hard to usefully extend and rather than try to deprecate features and slowly ease in a new interface, we've released Email::Sender which fixes these problems and others. As of today, 2008-12-19, Email::Sender is young, but it's fairly well-tested. Please consider using it instead for any new work. So, you may consider to use Email::Sender instead. For testing of this module, you could take a look at: http://search.cpan.org/~rjbs/Email-Send-2.197/lib/Email/Send/Test.pm Well, be that as it may, Email::Sender is still Beta and has only been out for about 6 months. Email::Send has been out for 5 years and is more likely to work for most cases. Forty+ years of computer experience has taught me not to be an early adopter and to stay off the bleeding edge! Mkay. Stay with Mail::Sender then. It's both tried and supported. Or go with MIME::Lite. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Please, I need help!!!
From: Jim Gibson jimsgib...@gmail.com On 6/11/09 Thu Jun 11, 2009 11:00 AM, Phillip fibbe...@gmx.net scribbled: Hallo @ all, i am new in this domain(perlscript) and i have a question.i have a array,i sort it,i get the last element of the array but i want to get the next element after this one.how can i do this? There is a language called Perlscript that is based on Perl but not the same. Are you asking about that language or about Perl itself? Are you sure? Any pointers? As far as I know ActiveState has/had something called PerlScript, but it's not a different langauge. It's just a scripting engine for Windows Scripting Host, Internet Explorer and MS IIS/ASP. Just a DLL that allows you to use Perl in those environments. Not a different language. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: better way to write this
From: raphael() raphael.j...@gmail.com It is actually very enlightening to read all the post on this list. Most of the stuff actually goes over my head as I have no need/knowledge of CGI or dbase. Just some text processing. I am new to Programming/Perl (chapter 5 Learning Perl). I also read a little about 'system() exec(). This is my first actual 'useful' Perl script!! I had written this as a Bash script then converted it to Perl. --code-- #!/usr/bin/perl use 5.010; apart from the (pretty useles say()) there is nothing 5.10 specific in the code. I do think say() is not something I would want to make my scripts incompatible with older perls for. use strict; use warnings; my ($A, @B, @C, $D); Do use meaningful variable names! And declare them together with the definition, not upfront. $A = 'http://abc.com/texts/files/getthisfile_'; # For files that are numbered by 01.txt # Also can append a '0' to $A still use @C @B = qw { 01 02 03 04 05 06 07 08 09 10 }; Have a look at spritf(). # For files that are numbered by 1.txt @C = (1..10); $D = '.txt'; foreach my $i (@C) { system 'wget', ${A}${i}${D}; # I know wget can read from a file. # say ${A}${i}${D};# say $A$i$D; # Which is correct? both work! } --code-- Is there a better way to write this without modules? OR is it just too simple just fine written this way? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: better way to write this
From: John W. Krahn jwkr...@shaw.ca Jenda Krynicky wrote: From: raphael() raphael.j...@gmail.com It is actually very enlightening to read all the post on this list. Most of the stuff actually goes over my head as I have no need/knowledge of CGI or dbase. Just some text processing. I am new to Programming/Perl (chapter 5 Learning Perl). I also read a little about 'system() exec(). This is my first actual 'useful' Perl script!! I had written this as a Bash script then converted it to Perl. --code-- #!/usr/bin/perl use 5.010; apart from the (pretty useles say()) there is nothing 5.10 specific in the code. I do think say() is not something I would want to make my scripts incompatible with older perls for. use strict; use warnings; my ($A, @B, @C, $D); Do use meaningful variable names! And declare them together with the definition, not upfront. $A = 'http://abc.com/texts/files/getthisfile_'; # For files that are numbered by 01.txt # Also can append a '0' to $A still use @C @B = qw { 01 02 03 04 05 06 07 08 09 10 }; Have a look at spritf(). $ perldoc -f spritf No documentation for perl function `spritf' found ;-( Silly typos. perldoc -f sprintf Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Working with a hash within an object
From: Steve Bertrand st...@ibctech.ca Hi all, I know this is a no-brainer, but I'm drawing a blank after coding all day (I'm not a coder by trade). I'm trying to write a test program for a function I'm accessing from a module I wrote years ago, and because I'm over-tired, I can't remember how to (or find how to) iterate over the items within an object. This is literally my test program. The $user object contains a couple dozen vars. One of them is shown in a print statement with the expected output as a comment. The following (and numerous variants of it) do not work. How do I properly iterate through all of the items in '$user'?: code below #!/usr/bin/perl use warnings; use strict; use EagleUser; my $user = EagleUser-new(); $user-build_inf_user('steveb'); print $user-{'login_name'}\n; # outputs 'steveb' as expected while ( my ($key, $value) = each($user) ) { while ( my ($key, $value) = each(%$user) ) { print $key = $value\n; } end code Cheers, Steve It doesn't matter whether it's an object. It's a hash reference so you can treat it as such. And since each() expects a hash, not a hash reference, you have to dereference. That is put a % in front of the $user. HTH, Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/