Questions tagged [perl]

27529 questions
1

votes
2

answer
562

Views

EXEC PID for perl files

I have a Perl file which has an exec command in it. I was wondering if there is someway I can find the P.I.D of that process??? Then the exec command has another exec command in it. So is there a way I can get the P.I.D of the latest exec (in depth) being executed at the moment? I am using Perl, I...
ban
1

votes
3

answer
1.4k

Views

Read multiple lines from console

How to read multiple lines from console in Perl? I have used @a = ; but I am unable to come out of that statement. Evertime I hit enter it goes to new line. I have read to hit ctrl+d to end the input but it does not seem to work.
niko
1

votes
1

answer
47

Views

exchanging Unicode char ruins char before this unicode char

I have a big list with unicode char's, which i want to exchange with some ASCII chars with following code (This code does some stuff more): while ($Zeile=) { @Zeile=split('\t',$Zeile); $i=0; foreach(@Zeile) { if ($i>1) { $entry=$_; $entry=~s/\(Details\)/ /; $entry=~s/\x{00BC}/.25/; $entry=~s/\x{00B...
Tigerle
1

votes
1

answer
252

Views

IPC::Run failure - Unexpected SCALAR in harness() parameter 3

I try to run simple script use IPC::Run qw (run timeout); run "date", \$in, \$out, \$err, timeout( 10 ) or die "err: $?"; print "Date is $out \n"; but it failure with error : Unexpected SCALAR(0x1e52f80) in harness() parameter 3 at t.pl line 2 Unexpected SCALAR(0x1e52f08) in harness() parameter 4 a...
user2921250
1

votes
1

answer
82

Views

Logs are written asynchronous to log file

I have come across strange scenario where when I am trying to redirect stdout logs of perl script into a log file, all the logs are getting written at the end of execution when script completes instead of during execution of the script. While running script when I do tail -f "filename", I could able...
lazyboy
1

votes
1

answer
645

Views

Using CPAN to install Dancer and dependencies

I am trying to create a sample web service using Dancer. I am using Ubuntu 10.04 as my OS. I installed Dancer and dependencies using CPAN client and can also do dancer -a MyApp However, when I try to run the app.pl file, the code throws an error saying YAML.pm not found. I am sure this file was dow...
karmanaut
1

votes
1

answer
170

Views

Perl: Delete keys in hash that don't exist as elements in array

I have an array of key names and need to remove any keys that are not in this list from a hash. I gather deleting keys in a hash is a Bad Thing while iterating over it, but it does seem to work: use strict; use warnings; use Data::Dumper; my @array=('item1', 'item3'); my %hash=(item1 => 'test 1', it...
Tim Jones
1

votes
1

answer
1.2k

Views

perl: save workbook with Win32::OLE not possible

I've following simplified script (i'm not able to change the Win32:OLE) use warnings; use strict; use Cwd; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my $excel = Win32::OLE->new('Excel.Application'); my $workbook = $excel->Workbooks->Add; my $worksheet = $workbook->Worksheets(1);...
MemLeak
1

votes
2

answer
322

Views

Develop a program to analyze the directory structure of a Linux disk and identify any files larger that 500kbytes

I'm trying to develop a program that will analyze the directory structure of a Linux disk and identify any files larger that 500kbytes. #!/usr/bin/perl use File::Find::Rule; use warnings; my $filelist; sub buildFile { open ($filelist, ">", "filelist.txt") || die $!; # File find rule and # Provide sp...
C.Younes
1

votes
2

answer
141

Views

Can't find Unicode property definition “o” - Regular expression is not working in perl

I am trying to capture a sub-string from a string for that i am using regx but its is not working. The error which i am getting is Can't find Unicode property definition "o" I am using Windows machine for running the below code. Here is the code : use strict; use warnings; my $path = 'C:\APTscrip...
user59053
1

votes
2

answer
1.4k

Views

How to make a clone of DateTime object

I have some code as follow: my $d1 = $start_date; $c->log->debug(Dumper($start_date)); my @date_range; while($d1 day(); $d1->add(days => 1); } How can I do to prevent $start_date changed?
hn19799
1

votes
2

answer
909

Views

Content-Type setting for .MTS files

In my application i like to provide file download facility. How can I set the content types for .MTS files. for example: if ($fileName =~ /\.pdf$/i) { ## for pdf files print "Content-Type: application/pdf", "\n"; print "Content-Disposition: Attachment; filename=$fileName", "\n\n"; print $File; }elsi...
user142847
1

votes
2

answer
2.5k

Views

How to find folder size in Perl using File::stat module?

Below is the Perl script to find the file size using File::stat module: #!/usr/bin/perl use strict; use warnings; use File::stat; my $directory = "/home/dinkar/index.html"; my $dirStats = stat($directory); my $size = $dirStats->size; printf("Size of %s: %d", $directory, $size); printf("\n"); I...
user2201935
1

votes
2

answer
528

Views

How to convert perl modules into deb packages?

My team is delivering a product that requires some perl modules, and since we deliver a full OS installer (Ubuntu 12.04) we want those modules as .deb packages. I've been able to build some other perl (like Algorithm::LUHN, Env::C, Linux::PID and Config::Properties) by following the instructions her...
Diego Villa
1

votes
1

answer
1k

Views

Accessing Mojolicious helpers from a module using Mojo::Base?

I have an existing application (my website) that I'm doing some code tidying in, and the tidy up is following the same sort of idea as the Mojo::Pg example here, with separate model and controller files to keep things defined. My site accesses both Flickr and Last.fm's APIs, and I have a helper defi...
VirtualWolf
1

votes
2

answer
110

Views

delete a key from a hash of array but I get Use of uninitialized value in hash element

I would like to know how to remove a key from a hash of array. Given the following file as a simple example, forth column is always the third column in the paired match and data in not sorted. .... NS501570 WWW 3009824 3009848 .... NS501572 WAD 3009848 3009898 .... I would lik...
Tahmtan Ebrahimi
1

votes
1

answer
110

Views

how to increment hash of hash in perl

failing to properly populate a HoH using this code: when i run the loop using below: while (my $form = $form_rs->next ()){ my $menu=$form->get_column("fmenu"); my $script=$form->get_column("fscript"); my $name=$form->get_column("ftitle"); $itemList->{$menu} = { $script => $name }; } print Dumper $it...
rajeev
1

votes
1

answer
395

Views

Convert long file name to short file

I have perl script file that contains variable that has long file name like "C:\Program Files\Some Folder\MyFile.txt". The file mentioned in the path does not exist. How do i convert this into short file name (8.3) format?
Asdfg
1

votes
2

answer
69

Views

Accessing Sibling Elements in XML DOM using Perl?

For my problem I am having a user enter a string to search for a provider, then the provider as well as some select plan information appears in the console. However, I cannot find out how to print out a select provider + the other information needed all in one. For example: Vodafone || 12 months ||...
Brendon C.
1

votes
2

answer
369

Views

How do I use Perl XML::LibXML to parse XML data using findnodes and findvalue

I am trying to parse XML using XML::LibXML module. The XML data structure has node called which encloses two child nodes and . I want to parse each of these and build a hash data structure. I could come up with below code to achieve it but I feel there would be a better way to do it. use strict;...
chidori
1

votes
3

answer
443

Views

Using LibXML and XPath To Find Node With Colon (Local Namespace)

I'm trying to get the attribute @id1 from in the below XML: [email protected] The only information that I can pass in is the email address [email protected] I'm using XML::LibXML and XML::LibbXML::XPathContext as below: my $dom = XML::LibXML->new->parse_file( $xml_file ); # XML contains as above my $xpc...
est
0

votes
0

answer
7

Views

how to solve the “Experimental values on scalar is now forbidden” problem in perl

In Perl 5.26.2 I get: Experimental each on scalar is now forbidden at a.plx line 67. Type of arg 1 to each must be hash or array (not private variable) at a.plx line 67, near "$val)" Execution of a.plx aborted due to compilation errors. Where line 67 is the while in 67 while (my ($ip, $va...
georgetovrea
0

votes
0

answer
4

Views

Perl: Connecting to Walmart API to load items Unsupported Media type error

We are trying using the marketplace.walmartapis.com api to bulk list items and it is returning unsupported media type for xml item feed We are using Perl and are able to perform other commands to update inventory and pricing, check orders, lookup feeds and skus etc. The token SHOULD be good, as we r...
1

votes
3

answer
2.5k

Views

How to replace string in Perl?

I am very new to Perl. I am trying to do a simple string substitution but could not succeed. #!/usr/bin/perl $var = "M4S120_appscan"; $var1 = "SCANS"; $path =~ s/$var/$var1/; print "Path is $path" Output should be "Path is SCANS" but it prints nothing in 'output'
Sathish Kumar
1

votes
1

answer
672

Views

How do I use encode_json with string in Perl?

Here is my code that I try to open the file to get data and change it to UTF-8, then read each line and store it in variable my $abstract_text and send it back in JSON structure. my $fh; if (!open($fh, '
Sleepz
0

votes
0

answer
9

Views

How to bypass magic hooks when using hash or array elements

I'm trying to use Variable::Magic in order to catch when an element of a hash is modified: use Variable::Magic qw(cast wizard); my %h = (a => 1, b => 2); cast %h, wizard store => sub { warn "store: @_\n"; my $k = $_[2]; cast $_[0]{$k}, wizard set => sub { warn "$k set to ${$_[0]}\n" } }; $h{a} = 33;...
Căcărău
1

votes
3

answer
332

Views

Perl MySQL utf8mb4 issue / possible bug

I am using Perl 5.20.2 and MySQL 5.5.57 on a Debian 8 machine. I recently discovered that MySQL's utf8 tables are limited to three-byte-characeters. As a consequence I can not store emojis. So, I tried utfmb4 tables which are supposed to address the issue. I changed the table from utf8 to utf8mb4 fr...
Marcus
1

votes
2

answer
51

Views

Perl: not an array reference while calculating array size

I'm trying to untangle some legacy code where an operation is done on $value iff its size is more than x (where x is a hard coded int). This is what it currently looks like: if (scalar(@{$value}) > x) { ... } As with all legacy code, this $value can be almost anything (hash, scalar, array) although...
Abdo Salem
0

votes
2

answer
19

Views

Regex find and replace inbetween Latex enviroment

I'm trying to come up with a regex to use in find and replace so I can find all '(' characters used inside of the align environment. Example text: Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum (Lorem Ipsum Lorem Ipsum ) Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum \begin{align} \...
Sam Palmer
1

votes
1

answer
68

Views

Using look-ahead/behind on complex search in R/Perl regex

I can't figure out how to utilize lookaheads/behinds in a regular expression to find matches across individual search bits (?) of the word/motif I'm searching for. In a set of DNA strings, I need to match TGGA + one C or T + 0-4 A/C/T/G + >= 5 C/T, but don't want a GT anywhere in the match. I've fi...
GenesRus
1

votes
2

answer
110

Views

In Perl, how to match two consecutive Carriage Returns?

Hi StackOverflow buddies, I'm on Windows platform; I have a data file but something wrong happened and (I don't know why) all combinations of "Carriage Return + New Line" became "Carriage Return + Carriage Return + New Line", (190128 edit:) for example: When viewing the file as plain text, it is: W...
katyusza
1

votes
2

answer
45

Views

How to make “prereqs” of CPAN::Meta::Spec require a distribution instead of a package?

I'm researching about how to package some of my Perl apps and better manage their dependencies to make distribution easier for me and my customers, which most likely doesn't include uploading to CPAN at all. Instead, I would provide custom repos if necessary or, more likely, access to SCMs like Subv...
Thorsten Schöning
1

votes
1

answer
41

Views

UTF-8 encoded JSON file, trying to parse with JSON module - wide character

I have a pretty simple script in Perl: use JSON; use open qw/ :std :encoding(utf8) /; #my $ref = JSON::decode_json($json_contents); my $path = "/home/chambres/web/x.org/public_html/cgi-bin/links/admin/booking_import/import/file.json"; my $json_contents = slurp_utf8_file($path); my $ref = JSON->new-...
Andrew Newby
1

votes
1

answer
40

Views

How to enable CORS for Catalyst

Having a Perl Catalyst application, which produces JSON, I need to read that JSON content using jQuery within an HTML page, served by an Apache server. Both applications, Catalyst and Apache are running on the same host. When I access the Catalyst URL from Apache I get the error Access to XMLHttpR...
1

votes
1

answer
59

Views

Perl regex for emails with multiple TLD

I have a regex that is to only match alphanumeric characters,".", and "_" both before and after the @ sign. It is to match only the following TLDs: com, org, edu, gov, uk, net, ca, de, jp, fr, au, us, ru, ch, it, nl, se, no, mil, biz, io, cc, co, info For example, it should match sample22_test.teste...
learningunix717
1

votes
2

answer
35

Views

How to split a long file and printout to different text files by Perl?

I have a long list text file with 3 column. The input file: XIGO XIGO_24480 Xigou XIGO XIGO_24481 Xigou XOLO XOLO_Z1E01 Xoloitzcuintle XOLO XOLO_Z1G01 Xoloitzcuintle YORK TYo_0GT393 Yorkshire Terrier YORK TYo_0GT394 Yorkshire Terrier I want the output text files w...
Victor.H
0

votes
2

answer
29

Views

Wild card matching

I need to match a sentences which contains both wild card character \ and . in same sentence.How to do it with Perl? Say suppose my file has following sentences : ttterfasghti. ddseghies/affag hhail/afgsh. asfsdgagh/ adterhjc/sgsagh. My expected output should be : hhail/afgsh. adterhjc/sgsagh.
cherry
0

votes
1

answer
13

Views

I am having problems trying to print this hash using perl

I am trying to work through a problem where I created a hash using push @{ $test{$onecell2}{$onecell3}{$onecell4} }, $onecell1; The reason for using this is due to the fact that the first 3 are repeated with multiple values which is the oncell1. I am not able to print the hash because at the fourth...
ary
1

votes
1

answer
423

Views

couldn't start TLS [Perl]

i'm trying to send an email with perl. my code run on linux with no error. but when i run my code on windows server 2008 r2 , perl sys : Couldn't start TLS: SSL version SSLv3 not Supported. my perl code : #!/usr/bin/perl use Net::SMTP::TLS; use 5.010; my $mailer = new Net::SMTP::TLS( 'smtp.mail.yaho...
user3001228
5

votes
3

answer
96

Views

Perl optimizer question: Will the perl compiler optimize away all of these temporary variables?

I've got a pretty simple piece of arithmetic, but for readability and correctness, I've expanded it out into a bunch of temporary variables. It's easier to read, change, and examine partial pieces of the expression. My question is, will this code take a run-time beating just because it's expanded?...
Erik Bennett

View additional questions