spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » PERL » Page 1
PERL Unicode Escape string pass from command line argument wrong output
In the first snippet, you assign the following to $string: https://docs.google.com/...downloadu0026revid... In the second snippet, you assign the following to $string: https://docs.google.com/...download0026revid... In a Perl double-quoted string literal, u causes the next character to be uppercased. You need to escape . my $string = "https://docs.google.com/...download\u0026revid...";

Categories : Perl

Perl process crashes after handling signal
Your program exits because the accept returns false because it got interrupted by a signal. You want while (1) { my $client = $srv->accept(); if (!$client) { next if $!{EINTR}; die(sprintf(STDERR "[%s] accept: %s ", basename($0), $!)); } print(STDERR "accepted new client "); serve_client($client); }

Categories : Perl

Marpa: Can I explicitly disallow keywords as identifiers?
I don't know how to express such a thing in the grammar. You can introduce an intermediate non-terminal for Identifier which would check the condition, though: #!/usr/bin/perl use warnings; use strict; use Syntax::Construct qw{ // }; use Marpa::R2; my %reserved = map { $_ => 1 } qw( AND ); my $grammar = 'Marpa::R2::Scanless::G'->new( { bless_package => 'main', source => (

Categories : Perl

Perl: Import text, containing ÅÄÖ, from file
Just tell Perl what encoding the file is in: open FILE, '<:utf8', $filename or die $!; Or, if you want to check the encoding, use open FILE, '<:encoding(UTF-8)', $filename or die $!;

Categories : Perl

error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
So, first problem: You're using Net::SSH modules, but using 'system' commands to do the dirty work. One or other is redundant. Inlining perl into an ssh runs a risk of interpolation errors - how do you know where the ' is getting handled? (e.g. your shell, ssh, remote shell, perl). What are you trying to do with your inlined perl? It looks like a very complicated way of doing ps -ef | grep top

Categories : Perl

DBIx::Class chaining resultsets with same table in prefetch
If you change your final version to this, it should work: $self->db->resultset('Category') ->with_translation($lang)->as_subselect_rs ->with_products($lang)->as_subselect_rs ->display; I think it will work. The problem is that it might break the prefetch, I'm not positive... Another thing to be aware of is that you are prefetching two sets of has manys. I be

Categories : Perl

Time as input, print timetable in Perl
Try using the DateTime module. For example: use DateTime; my $h = 7; my $m = 55; my $dt = DateTime->new( year => 2014, month => 11, day => 24, hour => $h, minute => $m, ); printf "%02d:%02d ", $dt->hour, $dt->minute; # prints "07:55" $dt->subtract(minutes => 15); printf "%02d:%02d ", $dt->hour, $dt->minute; # prints "07:40" #

Categories : Perl

compare values of different tables perl
Fortunately, I still have the code from last time in my notepad. I've made a couple of updates, based on the changed requirement. This should do what you ask. (Feeding the table data in without inlining it is left as an exercise for the reader). use strict; use warnings; use Data::Dumper; my %table2; while (<DATA>) { #stop reading if we've finished with table2 last if m/^tabl

Categories : Perl

Automatically increasing ID generation using PERL
Keep a counter $i = 0; every time a table (either in a for or a while loop) is found do an incremental step and use it to declare the name of your table. $i++; $table_name = "section-table-$i" To get your 4 digit id, use sprintf. http://perldoc.perl.org/functions/sprintf.html $i++; $table_id = sprintf<%04s> ,11; $table_name = "section-table-$table_id"; note the double quote. pr

Categories : Perl

Syntax Error, first line after dostuff
I think you're having some basic confusion about how the Perl syntax works. Allow me to back up a step. Here's a while loop that prints a message every thirty seconds: while(1){ print "hi, mom! "; sleep 30; } Here's a while loop that calls dostuff() every thirty seconds while(1){ dostuff(); sleep 30; } Got that? Now we need to define dostuff(), so we add this: sub dostuff

Categories : Perl

Delete files in a folder using Perl
remove all your config lines ( are they even perl? ) CONFIG_DIR=`pwd` VENDOR=ericsson-msc RELEASE=v1 BASE_DIR=/appl/virtuo/gways and system ("cd /appl/virtuo/gways/config/ericsson-msc/v1/spool/input_d; rm -rf *TRAR") should work but you should really be using perl code (unlink, etc) I suspect you are confusing the usage of perl with how you will use awk in bash scripts.

Categories : Perl

Perl '-d' operator is not detecting a directory
The values of $_ which are read in by the perl one-liner include a trailing newline. Therefore, -d does not even find the directory, let alone recognize that it is a directory. Here is a solution: ...some commands... | perl -ne 'chomp $_; print "$_ " unless -d $_ ;' Note the use of chomp to remove the trailing newline. In conjunction with -n or -p, -l not only adds a newline to printed stri

Categories : Perl

Perl appending text to new line
Adding user to end of file, only if it is not already taken, my $taken = 0; while (my $line = <FILE>) { chomp $line; # splits each line into three fields my @fields = split "," , $line; if ($user eq $fields[1]) { print "Username is taken. "; $taken = 1; last; } } if (!$taken) { print FILE "$user "

Categories : Perl

write_timeout in IO::Socket::Timeout
With this code, whatever value i set for read_timeout, socket is closed after that expires. If i set read time very large value, and my code doesnt write(print) anything into socket, shouldn't it be closed after write_timeout expires? These are no timeouts to determine an idle socket, but instead timeouts for actions. That is if you do a blocking read it will block at most the time you've spe

Categories : Perl

Using ForkManager and Perl properly?
To lower the number of instances created, yes, just lower 500 (in both cases) to something else. Parallel::ForkManager is a way of using fork (spawning new processes) to handle parallel processing. The parameter passed to new() specifies the maximum number of concurrent processes to create.

Categories : Perl

Is a cyclic dependency solved with require?
For purely object-oriented code, there is no circular dependency problem. You can quite happily have something like: # AAAA.pm package AAAA; use strict; use warnings; use BBBB; sub new { my $class = shift; my ($i) = @_; bless { b => $i > 0 ? BBBB->new($i-1) : $i }, $class; } 1; # BBBB.pm package BBBB; use strict; use warnings; use AAAA; sub new { my $class =

Categories : Perl

Posting metric to google analytics from perl script
I am able to post analytics from my php scripts, but could not post analytics from perl script. I solved my problem as follows. Created an utility php script and called that php script from my perl script. Then it worked. <?php $ec = $_GET['ec']; $ea = $_GET['ea']; $el = $_GET['el']; $ev = $_GET['ev']; // Send event tracking as well. $url = 'http://www.google-anal

Categories : Perl

How can I check if a user enters my page the first time?
Please do you a favor and use at least the CGI module, it will make your life much easier and safer. use CGI qw/:standard/; use CGI::Cookie; %cookies = CGI::Cookie->fetch; if ( exists $cookies{VISITED} ) { checkoutform(); } else { my $cookie = CGI::Cookie->new(-name=>'VISITED',-value=>1, -expires='Fri, 31-Sep-2015 24:00:00 GMT'); print header(-cookie=>[$cookie]

Categories : Perl

Sorting arrays of intervals in perl?
You need to extract first number for every element, and do numerical comparison using <=> operator, my @array = qw(1-5 7-9 10-15 20-58 123-192 234-256); my @sorted = sort { my ($aa,$bb) = map /^([0-9]+)/, $a,$b; $aa <=> $bb; } @array;

Categories : Perl

Perl: How to get the link target of a soundcloud feed mp3
You can download the mp3 file with LWP::Simple: use strict; use warnings; use LWP::Simple; my $url = "http://feeds.soundcloud.com/stream/176971524-thetalkshow-thetalkshow-100.mp3"; getstore($url, "my-file-name.mp3");

Categories : Perl

Uninitialized value in concatenation
You are using the File::stat module. This module implements a stat functionality that overrides Perl's built-in. And it returns an object instead of a list. So this: my $sb = (stat($file))[7]; Causes $sb to be undefined, because there is only 1 object in the list. What you do is use the modules functions instead: my $sb = stat($file)->size();

Categories : Perl

Perl code - pipe "|" in `open()` statement
That stray | is a way of Perl of saying that you want the output of that command to be made available to your program. There are several equivalent forms. Take a look here: open - perldoc.perl.org. Specially at the line that says: open(FOO, "cat -n '$file'|");

Categories : Perl

perl command line backticks with matrix
OK, pretty fundamentally - to do what you're trying to do directly isn't possible. An array is a memory state, and it doesn't conveniently package up to pass it around. That's why you're getting things like ARRAY(0x6c0cb8) - that's because it's the memory address the array (or subelements) occupy. So however you do this, you will need to render your array first, and then parse it in your subprogr

Categories : Perl

Perl OO - Creating a list of objects
You have two main problems Your initialisation of $self $self = { _id => $id, _title => (), _words => () }; is very wrong, because the empty parentheses () add nothing to the structure. If I dump $self after this I get { _id => 1, _title => "_words" } You are also blessing $self twice, but there is no problem with that: it is more of an indication that you don't

Categories : Perl

extract gene-id + function annotation from .gff
You can use use Bio::FeatureIO for that. Below an example for your data: use strict; use warnings; use Bio::FeatureIO; # read infile "my.gff" my $in = Bio::FeatureIO->new(-file => "my.gff" , -format => 'GFF'); # write to outfile "out.txt" open(my $fh, '>', 'out.txt') or die $!; print $fh "Gene-ID functionannotation "; while ( my $feature = $in->next_feature() ) { my ($f

Categories : Perl

How to receive parameters and values from POST method in Perl CGI?
If they are in the URL, it's GET, not POST. For GET: How can I read the URL parameter in a Perl CGI program? For POST: how to get POST values in perl

Categories : Perl

Perl - Parse text file with tags for data dump into new text file
Please check this one: use strict; use warnings; use Cwd; #Get Directory my $dir = getcwd(); #Grep files from the directory opendir(DIR, $dir) || die "Couldn't open/read the $dir: $!"; my @AllFiles = grep(/.txt$/i, readdir(DIR)); closedir(DIR); #Check files are available if(scalar(@AllFiles) ne '') { #Create Text Files as per Requirement open(PAP, ">$dir/Papers.txt") ||

Categories : Perl

How with perl and Net::OpenSSH can I detect if the remote side only handles protocol 1?
Capture the master stderr stream and check it afterwards. See here how to do it. Another approach you can use is just to open a socket to the remote SSH server. The first thing it sends back is its version string. For instance: $ nc localhost 22 SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-8 ^C From that information you should be able to infer if the server supports SSH v2 or not. Finally, if you also nee

Categories : Perl

how can i ssh into a server, and read a pid file and bring back the #?
Easiest way is with backticks. my $output = `ssh server -l myid -i /home/myid/.ssh/authorized_keys some_command`; $output will contain the output of your ssh command.

Categories : Perl

How can I improve the syntax of my AUTOLOADed method names?
It's possible if you can tell that user is a namespace or member rather than a call. package Class; sub AUTOLOAD { (my $method = our $AUTOLOAD) =~ s/^.*:://s; return if $method =~ /DESTROY/; my $self = shift; return bless([$self, $method], 'Class::Helper'); if $self->is_namespace($method); perform_rpc_call($self, $method, @_); } package Class::Helper; sub AUT

Categories : Perl

Extract the unique intervals from two arrays in perl?
Process the files line by line. If there's no overlap, report the interval that starts earlier and advance its file. In case of an overlap, advance both files. #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @F; open $F[0], '<', 'file1.txt' or die $!; open $F[1], '<', 'file2.txt' or die $!; # Skip headers. readline $_ for @F; my @boundaries; my @results; sub earlier {

Categories : Perl

find values in a range of 2 values
I think you're tackling this backwards. Parsing table2 first into a hash makes the problem a lot easier. Because then you can iterate table1 and check for any values in the range in question. use strict; use warnings; use Data::Dumper; my %table2; while (<DATA>) { #stop reading if we've finished with table2 last if m/^table1/; next unless m/^rs/; my ( $col1, $col2 ) = sp

Categories : Perl

perl foreach array result from a database
Is fetchrow_array what you need? while (my ($id, $status, $process_id, $error_count) = $sth->fetchrow_array) { if (1 == $status and grep $_ == $process_id, @some_array) { # do something } }

Categories : Perl

Attempt to embed Perl in C on Windows
It will not work if you are in a different path than your script and c files. Remove the absolute paths K:ScriptsEmbedHello_3 The "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption? If hello.pl does not use any libs, yes. int main(int argc, char **argv, char **env) { argv[1] = "-Ilib"; argv[2

Categories : Perl

Perl adding date/time to a file name
There is no easy way to do that. The best you can do is to make a temporary directory, fetch the file there using the default name, then rename it to the name you need. Use File::Temp::tempdir: use File::Fetch; use DateTime qw(); use File::Temp qw( tempdir ); sub getDateUtility { return DateTime->now->strftime('%m_%d_%Y') } sub fetchFile { my ($url, $destination) = @_;

Categories : Perl

How to calculate a date a week ago from today
DateTime version use DateTime; my $now = DateTime->now(time_zone => 'local')->subtract(weeks => 1); print $now->ymd, ' ',$now->hms; Date::Calc version Instead of one week you can subtract 7 days using Date::Calc module use Date::Calc qw(Add_Delta_Days); my @date = Add_Delta_Days( 2014, 11, 21, -7 ); print join('-', @date); OUTPUT 2014-11-14

Categories : Perl

How to get files names with specific extension from a folder in perl
Yes, there are much more complicated ways, like opendir, readdir and a regex filter. They will also give you the hidden files (or dotfiles): opendir DIR, $DIR or die $!; my @filearray = grep { /.(abc|llc)$/ } readdir DIR; closedir DIR;

Categories : Perl

How can I change the date time formats in Perl?
my $str = 'Fri Nov 21 2014 15:04:32'; my @months =('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); my ($day,$mon,$date,$year,$time) = split(' ',lc($str)); my %month_hash; @month_hash{@months} = (1 .. 12); print "$year-$month_hash{$mon}-$date $time"; try this its crude method but works for your requirements. use date::manip for flexible usage

Categories : Perl

Perl file I/O issues: Script erasing all file contents instead of just removing numbers.
You used @array = <in>; instead of @array = <$in>;! When you actually tried to read the file using while (<$in>), it had already been clobbered by open '>'. s/d/ / doesn't just remove a digit; it adds a newline in its place. #!/usr/bin/perl use strict; use warnings; my $qfn = 'rmv_num_lines.txt'; open my $in_fh, '<', $qfn or die "Can't open $qfn: $! "; my

Categories : Perl


Recently Add
Perl script to print out all the lines containing a keyword and the line below it
PERL Unicode Escape string pass from command line argument wrong output
Perl process crashes after handling signal
Marpa: Can I explicitly disallow keywords as identifiers?
Perl: Import text, containing ÅÄÖ, from file
error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
DBIx::Class chaining resultsets with same table in prefetch
Time as input, print timetable in Perl
compare values of different tables perl
Automatically increasing ID generation using PERL
Syntax Error, first line after dostuff
Delete files in a folder using Perl
Perl '-d' operator is not detecting a directory
Perl appending text to new line
write_timeout in IO::Socket::Timeout
Using ForkManager and Perl properly?
Is a cyclic dependency solved with require?
Posting metric to google analytics from perl script
How can I check if a user enters my page the first time?
Sorting arrays of intervals in perl?
Perl: How to get the link target of a soundcloud feed mp3
Uninitialized value in concatenation
Perl code - pipe "|" in `open()` statement
perl command line backticks with matrix
Perl OO - Creating a list of objects
extract gene-id + function annotation from .gff
How to receive parameters and values from POST method in Perl CGI?
Perl - Parse text file with tags for data dump into new text file
How with perl and Net::OpenSSH can I detect if the remote side only handles protocol 1?
how can i ssh into a server, and read a pid file and bring back the #?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.