I load the following YAML stream into a Perl's array and I want to traverse the array associated with Field2.
use YAML;
my @arr = Load(<<'...');
---
Field1: F1
Field2:
- {Key: v1, Val: v2}
- {Key: v3, Val: v4}
---
Field1: F2
Field2:
- {Key: v5, Val: v6}
- {Key: v7, Val: v8}
...
foreach (@arr) {
@tmp = $_->{'Field2'};
pr...
What are the differences between shell languages like bash, zsh, fish and the scripting languages above that makes them more suitable for the shell?
When using the command line the shell languages seem to be much easier. It feels for me much smoother to use bash for example than to use the shell profile in ipython, despite reports to th...
I was wondering when one should use s/// over tr/// when working with regular expressions in Perl?
...
@urls= $field =~ /<a.*?href="(.*?)".*?>.*?<\/a>/mgo; #multi-line, global, compile-once
@text= $field =~ /<a.*?href=".*?".*?>(.*?)<\/a>/mgo;
for ($count=0; $count<(scalar @urls); $count++){
print "\"".$text[$count]."\" goes to ->\"".$url[$count]."\"\n";}
What is the correct syntax to make this the same as the previous lines?
(@arra...
Why doesn't Perl 5 give me the name of the variable it is complaining about?
perl5.8.9 -we 'my $u; print "$u\n"'
Use of uninitialized value in concatenation (.) or string at -e line 1.
...
Don't want to sort the entries.
using this does not preserve the order as well
foreach my $val (keys %hash) {
...
}
...
Perl 5.10 introduced a proper switch construct with given/when and it seems like a powerful tool.
Currently however, perldoc perlsyn lacks some good examples.
One case where I found it handy lately was for using it with file test operators:
given (-d "foo/bar/") {
when (1) { ... } # defined is wrong as -d returns '' on a file.
...
This question is not Perl-specific, (although the unpack function will most probably figure into my implementation).
I have to deal with files where multiple formats exist to hierarchically break down the data into meaningful sections. What I'd like to be able to do is parse the file data into a suitable data structure.
Here's an examp...
#!/usr/bin/perl -w
use strict;
open (EVENTLOGFILE, "<eventlog.txt") || die("Could not open file eventlog file");
open (EVENTLOGFILE_NODATETIME, ">eventlog_nodatetime.txt") || die("Could not open new event log file");
my($line) = "";
while ($line = <EVENTLOGFILE>) {
my @fields = split /[ \t]/, $line;
my($newline) = "";
my($i) = 1;
...
I'm working on a couple of personal project to improve my Perl skills. Among other things they need to provide a GUI interface on different OSes. In the past what little GUI work I did on Perl used TK (and that was just working through some sample projects). I know that beyond TK, Qt and GTK are also options.
Are there others?
Among...
I just took notice to this generated by Catalyst.pl. It is obviously some sort of unannotated hack. What is the advantage of setting up a version string like this? I can't even figure out what they're trying to do.
our $VERSION = '0.01';
$VERSION = eval $VERSION;
...
Hi all:
I've researched online and found several interesting Perl modules/frameworks, such as HTML:Mason, HTML::Embperl, or the MVC Catalyst framework, etc,which can let me embed Perl inside html, similarly like PHP code inside html.
However, my Perl project must be uploaded to uni server where only limited privilege and resources are ...
I am matching a pattern and getting the line of the match using $.
I need to print the line matching before the particular pattern and after the particular pattern, e.g.:
line1
line2
line3
line4
line5
After my pattern matches line3, I want to print line2 and line4.
How can I do a pattern match in Perl? Can any one help me?
Thanks i...
Can anyone suggest the methods I could use...
I m on shared hosting now (cpanel)... I have access to perl modules, ruby, (No idea how they work)
...
I'm used to perl and new to R. I know you can read whole tables using read.table() but I wonder how can I use R to parse a single line from an input file.
Specifically, what is the equivalent to the following perl snippet:
open my $fh, $filename or die 'can't open file $filename';
my $line = <$fh>;
my ($first, $second, $third) = split ...
I've tried everything Google and StackOverflow have recommended (that I could find) including using Encode. My code works but it just uses UTF8 and I get the wide character warnings. I know how to work around those warnings but I'm not using UTF8 for anything else so I'd like to just convert it and not have to adapt the rest of my code t...
I'm designing a cross-platform map editor for an application I've developed, and I'm unsure what approach to take regarding language/gui library choice. Just for some basic info, the editor needs to parse and output xml files.
I'm most comfortable with C++, Lua, and Perl, but I'd also be willing to use Python (could use the practice). I...
I am trying to test a specific condition the will only occur if perl has a malloc that fails due to there being no memory left. I would like perl to die as quickly as possible. I figured the fasted way would be create some huge arrays like
perl -le '$_->[100_000_000_000] = 1 for \(@a, @b, @c, @d); <>'
But I had to kill it after my sw...
If you could explain the flow and how/why we can create a module to run with -Mm it will be helpful
...
I was inspired by Slashdot, I was heard that it uses very limited servers to support a lot of users with fast response. And there is a website named slashcode, not sure if slashdot uses its source code.
I am wondering if Perl is the best to write a high performance web page? I know using Apache or IIS will be having a lot of overhead?
...