Can I replace the binding operator with the smart match operator in Perl?
How can I write this with the smart match operator (~~)? use 5.010; my $string = '12 23 34 45 5464 46'; while ( $string =~ /(\d\d)\s/g ) { say $1; } ...
How can I write this with the smart match operator (~~)? use 5.010; my $string = '12 23 34 45 5464 46'; while ( $string =~ /(\d\d)\s/g ) { say $1; } ...
Strawberry Perl is "Open Source Perl for Windows that is exactly the same as Perl everywhere else". Vanilla Perl "provides a Perl distribution that is as close to the Perl core as possible." Strawberry Perl is built on Vanilla Perl. Both distributions come with a C compiler so that perl modules from CPAN that use XS can be built. What ...
First, please pardon my rusty Perl. I'm trying to modify Bugzilla's "whine.pl" to generate lists of bugs sorted by severity. So it gives me an array of hash references. Each hash contains a bunch of information about a particular bug (id, assignee, severity, etc). I want to sort the array by severity. What's the best way to do this? I'...
Edit: After reading the responses, I believe the answer is "don't do this", hence I marked an appropriate response as the official answer. Is there an easy way to get emacs to display perl switch statements like perldoc.perl.org's switch page? Here's the formatting on perldoc.perl.org: use Switch; switch ($val) { case 1 ...
I've written a simple test case based on Test::Perl::Critic which runs critic on every single source file in the repository (all_critic_ok). However, this test takes a long time, especially since I also use a Perl::Tidy policy. Normally, criticizing different files is not dependent on other critics, so I thought I could parallelize tho...
I don't think the following should work, but it does: $ perl -e '@a = qw/1222 2 3/; while (<@a>) { print $_ ."\n";}' 1222 2 3 $ As far as I know, Perl's <> operator shoud work on filehandle, globs and so on, with the exception of the literal <> (instead of <FILEHANDLE>), which magically iterates over @ARGV. Does anyone know if it's s...
I like to use the nifty perl feature where reading from the empty angle operator <> magically gives your program UNIX filter semantics, but I'd like to be able to access this feature through an actual filehandle (or IO::Handle object, or similar), so that I can do things like pass it into subroutines and such. Is there any way to do this...
But i hope to get some help. I want to associate a cell value in table with it's header. The header is not known, as it was generated by SQL query. Sizes as header came from SQL return result. So then put it into an array, @sizes = qw(S36 S37 S38 S39 S40 S41 S42); Now, if James has size S38. I want to print them as HTML table with s...
I have a file in below format. DATE Time, v1,v2,v3 05:33:25,n1,n2,n3 05:34:25,n4,n5,n5 05:35:24,n6,n7,n8 and so on upto 05:42:25. I want calculate the values v1, v2 and v3 for every 5 min interval. I have written the below sample code. while (<STDIN>) { my ($dateTime, $v1, $v2, $v3) = split /,/, $_; my ($date, $time) = split ...
I need to convert HTML documents (generated from DocBook XML documents) to the Wiki mark up language, in particular to the PM Wiki mark up language. The goal is to include the company's application operations guides in our newly created wiki. This means that I actually have two options: Convert the HTMLs (generated from DocBook XMLs) t...
Hi Everyone. In perl 5.8.5, if I do the following, I don't get an error: use strict; my $a = undef; foreach my $el (@$a) { ...whatever } What's going on here? Printing out the output of ref($a) shows that $a changes to become a valid array reference at some point. But I never explicitly set $a to anything. Seems kind of odd tha...
I need some help making this script... so far I think it should look something like this (I tend to use AWK a lot) #!/usr/bin/perl -w @filelist=( file1, file2, file3 ) print ("<html>"); foreach $filelist { print ("<table>"; print ("<td>"$filelist"</td>") foreach [line in the file] print ("<td>"$1, $2"</td>"); } print ("</...
I'll attempt to illustrate this with an example. Take a common example of a Hash of Hashes: my %HoH = ( flintstones => { lead => "fred", pal => "barney", }, jetsons => { lead => "george", wife => "jane", "his boy" => "elroy", }, simpsons => { lead => "homer",...
I have this Perl script sitting in the cgi-bin folder of my Apache server: #!/usr/bin/perl use strict; use warnings; $| = 1; print "Content-type: text/html\r\n\r\n"; print "Hello there!<br />\nJust testing .<br />\n"; my $top = 5; foreach (1..$top) { print "i = $_<br />\n"; sleep 1; } What I want to achieve here is a gradu...
I'm writing a tool in Perl that needs to scan for certain binary patterns inside an executable file on a Mac OSX. To avoid getting very many false positives, I want to restrict my search to the data/text segment of the executable, excluding the code segment and a few other things. How can I accomplish this? ...
The following lines of comma-separated values contains several consecutive empty fields: $rawData = "2008-02-06,8:00 AM,14.0,6.0,59,1027,-9999.0,West,6.9,-,N/A,,Clear\n 2008-02-06,9:00 AM,16,6,40,1028,12,WNW,10.4,,,,\n" I want to replace these empty fields with 'N/A' values, which is why I decided to do it via a regex substitution. ...
I tried this example in Perl. Can someone explain why is it true? if (defined sdf) { print "true"; } It prints true. sdf could be any name. In addition, if there is sdf function defined and it returns 0, then it does not print anything. print (sdf); does not print sdf string but if (sdf eq "sdf") { print "true"; } prints ...
Ever since British Summer Time ended in the UK last week my application has been seeing a very interesting bug. Here's an isolated Perl script which demonstrates the issue: #!/usr/bin/perl use strict; use warnings; use DateTime::Format::W3CDTF; use DateTime::Format::ISO8601; my $tz = 'Europe/London'; sub print_formatted_date { my ...
I don't know if "variadic" is actually the right word, but I'm talking about things that can take a list of values, like IN(). If you've been working with DBI for long, you've probably tried to do this: (Note: All examples extremely simplified for brevity) my $vals = join ', ', @numbers; my $sth = $dbh->prepare( "SELECT * FROM mytbl WH...
I'm currently working through some code katas in multiple languages (Ruby, Perl, Python)/frameworks (Rails, Django, Mojo). It seems every time I start a new project from scratch I end up tweaking files to my liking, even after using things like newgem, module-starter, script/generate, startapp, etc. For those who program in many differe...