I came across this syntax while reading a script. I am not sure what is the use of square brackets.
push @data, [ split //, $line ]; #printing this array gives crap values
Or to put into other words what is the difference between the above and the following?
push @data, (split//, $line); #printing this gives actual values
Any sugg...
Hi,
I have a simple script trying to learn about hashes in Perl.
#!/usr/bin/perl
my %set = (
-a => 'aaa',
-b => 'bbb',
-c => 'ccc',
-d => 'ddd',
-e => 'eee',
-f => 'fff',
-g => 'ggg'
);
print "Iterate up to ggg...\n";
while ( my ($key, $val) = each %set ) {
print "$key -> $val \n";
last if ($val e...
I gave up on sed and I've heard it is better in Perl.
I would like a script that can be called from the 'unix' command line and converts DOS line endings CRLF from the input file and replaces them with commas in the output file:
like
myconvert infile > outfile
where infile was:
1
2
3
and would result in outfile:
1,2,3
I would...
How to extract the data from a word doc using Perl?
...
How to find the image file type in Perl form website URL?
For example,
$image_name = "logo";
$image_path = "http://stackoverflow.com/content/img/so/".$image_name
From this information how to find the file type that . here the example it should display
"png"
http://stackoverflow.com/content/img/so/logo.png .
Supposer if it has...
This is my attempt to cut through extraneous issues raised "Why don’t my system calls work in the Perl program I wrap with pp?" I have created a simple Perl script on a linux system:
new-net:~/scripts # cat ls_test.pl
@ls_out = `ls -l`;
map { print "$_\n" } @ls_out;
$out = `sh out_test.sh`;
print "$out\n";
This script calls a simp...
I though this would be simple, but apparently I can't do:
script.pl *.ext
in the WinXP command processor.
Is there a built-in solution? (i.e. not a CPAN module?)
...
How can I make Data::Dumper write a dump into a file?
...
A few weeks ago I wrote an SNMP relayer for our ops group. They have some dumb devices that can only send traps to a single IP, and we have a monitoring system that listens on multiple IPs for availability. The code's dead simple, and essentially:
while (recv($packet)) {
foreach $target (@targets) {
send($target, $packet);
}
}...
I got this strange line of code today, it tells me 'empty' or 'not empty' depending on whether the CWD has any items (other than . and ..) in it.
I want to know how it works because it makes no sense to me.
perl -le 'print+(q=not =)[2==(()=<.* *>)].empty'
The bit I am interested in is <.* *>. I don't understand how it gets the names ...
So I am toying with some black magic in Perl (eventually we all do :-) and I am a little confused as to exactly how I am supposed to be doing all of this. Here is what I'm starting with:
use strict;
use warnings;
use feature ':5.10';
my $classname = 'Frew';
my $foo = bless({ foo => 'bar' }, $classname);
no strict;
*{"$classname\::INC"}...
I was inspired by another question to write a script (or rather a one-liner) to grab random Wikipedia pages.
Here's what I've got so far:
# Grab the HTTP header response from Wikipedia's random page link
curl 'http://en.wikipedia.org/wiki/Special:Random' -sI
# Search STDIN for the Location header and grab its content
perl -wnl -e '/Lo...
This was not written by me; it was written by someone who passed it down to me. I lost contact with the author of the code. I have been using this code for a few years and just now realized this error. It seems that the letter sequence rkey1 messes up the output.
For example turkey1 outputs as decryption as tur79y1. This Perl code shou...
Our web application works together with several web-services which we can't influence. After each workflow (tested with Selenium) a hook call to a web-service occurs. I would like to mock that server. Ideally, I want a HTTP server object which I can start and kill at will, and an URL dispatcher which would call certain subroutines in my ...
In the following Perl pattern:
while(<>) {
# do stuff
}
is there a way to get the name of the file that is presently open?
Just to be clear, I expect to receive many args, so that loop will process more than one file. I want the name of the file presently being processed.
...
I was bullied into giving a four hours Perl training. What topics should I cover?
There is a similar question already, but I found that question to be vague, and the answers equally so. So I'll be more specific in what my outline is.
To me, Perl is about getting things done. My Perl scripts are one-shot scripts intended to solve specif...
Hello friends,
I'm looking for a way to take the TEXT characters from a 4byte BINARY file to array or TEXT file,
Lets say my input file is:
00000000 2e 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 |................|
00000010 04 00 00 00 05 00 00 00 06 00 00 00 07 00 00 00 |................|
00000020 08 00 00 00 00 00 00 00 00 ...
How can I list all available UNIX commands from Perl?
...
Let's say I have a Perl file in which there are parts I need to run only when I'm called as a script. I remember reading sometime back about including those parts in a main() method and doing a
main() unless(<some condition which tests if I'm being used as a module>);
But I forgot what the condition was. Searching Google hasn't turned...
My program read other programs source code and colect information about used SQL queries. I have problem with getting substring.
...
$line = <FILE_IN>;
until( ($line =~m/$values_string/i && $line !~m/$rem_string/i) || eof )
{
if($line =~m/ \S{2}DT\S{3}/i)
{
# here I wish to get (only) substring that match to pattern \S{2}DT\S{...