Questions tagged [perl]

32934 questions
0

votes
0

answer
14

Views

DBD-Oracle-1.76 installation issue

I am setting up a new server for POSTGRESQL, so we have to migrate from ORACLE to POSTGRES while installing DBD-Oracle-1.76 package. However, we are getting error even though we have exported ORACLE_BASE, ORACLE_HOME, LD_LIBRARY, LD_LIBRARY_PATH. Here is what I have tried: make rm -f blib/arch/auto...
Abhinav
1

votes
2

answer
34

Views

How do print a sequence of characters (hex) as UTF8 characters in Perl?

I have a variable in Perl that is just a sequence of letters and digits: my $var = '48656c6c6f20576f726c64'; The sequence represents the string Hello World. I.e. one can think of it as 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x57 0x6f 0x72 0x6c 0x64, the hex representation of Hello World. How do I print $var...
user2426316
1

votes
1

answer
44

Views

How can I replace values in a deeply nested but arbitrary data structure?

I have a data structure that is arbitrary. The form is usually similar in that it consists of arrays and hashes about four levels deep, with about two to six values I'd like to change. A typical example: $VAR1 = [ undef, [ { '0' => 'some string' } ], undef, [ undef, { '1033' => 'another string ' } ]...
John O
1

votes
2

answer
42

Views

Writing to a file inside if statement not working in Perl

I've looked around here a bit and found similar questions but not exactly. If there is one, I apologize and please point me to it. I have the following code. I'm trying to create a csv file of simply an ID pulled from a filename and the filename itself. This is the ENTIRE script. use strict; use war...
Reverend Bubbles
1

votes
1

answer
45

Views

perl - remove bytes from a binmode string by looking up an array

I'm reading file in chunks using binmode() and wanted to strip out byte values that match any value in a static list @strip = (91, 92, 98, 107, 5, 64, 21, 13, 11, 12) what I'm doing in my script binmode($fh); read($fh,$data,20); %strip = (91=>1, 92=>1,98=>1,107=>1,5=>1,64=>1,21=>,1...
stack0114106
1

votes
2

answer
74

Views

Perl: push character to hash of array

I am calculating log-odds scores of sequences and returning the motif (small section of sequence) that gives the maximum score. I have code that calculates the maximum score for each sequence in my file, and I am having trouble storing the motif that gives that score. See my other post(s) for file f...
William
1

votes
3

answer
55

Views

extracting before digits before and after forward slash /

I have trouble with extracting the string before and after /. x before_slash [1] 'maximusa/b=(5/+1)' 'maximusa/b=(-4/1)' 'maximusa/b=(+3/-2)' I tried some but no luck!
Alexander
1

votes
2

answer
70

Views

Perl - Get the structure of a sqlite database using DBI

I need to test the structure of my SQLite database which is composed by a unique table with let's say 2 columns (id, name). I can't figure out the SQL query to get the table schema of my database. I am able to get all the content of the database using the DBI method selectall_arrayref(). However it...
AntMau
1

votes
1

answer
53

Views

Can't create unknown regex: $RE{some}{pattern}

I have a code here which throws the following error - 'Can't create unknown regex: $RE{some}{pattern} ' when I am running it using module Regexp::Common. The objective of the code is to read a file,search for a string and execute 2 conditions. First condition: if the function timing is present for a...
Kesha
1

votes
3

answer
47

Views

Replace the beginning of every line of a possibly multiline pattern

I'm trying to match a multiline pattern and modify every line matching this pattern including, the first one, so that a character will be added at the beginning of the line (+/-) For example, I have that : stuff above one-liner span stuff middle stuff inside other stuff stuff below And I want to obt...
ogr
1

votes
3

answer
106

Views

Perl extract group with lookbehind from different line

I've tried web search and have read several answers on stackexchange, still cannot grasp why command does not extract anything. At the end I want to extract group with lookbehind from different line, e.g. from Code>TEST1besttest2false
Alexei Martianov
1

votes
1

answer
51

Views

Parse::RecDescent and operators with quotes

I have something like the following: ((x=2 or y=3 ) and (r=3 and c=3) or (x=5 and g=6)) I defined: Token : /\w \= \d/ operator or|and expression : token operator(s) quoted_expression : '('expression')' query : expression (s)|quoted_expression(s) But I have a problem with parsing the above condition...
jsor
1

votes
3

answer
68

Views

How can I limit this term to a 3 piece hit?

It would be the real task to sadfsadf! Ghfgh% fgh65 %% of this text to replace the first 3 characters that are true for regexp, so replace it with 'o' sadfsadfoghfghofgh65o% #!/usr/bin/perl -w @list=; chomp(@list); foreach(@list) { if($_ =~ m/\W/) { # here is the problem because all the characters y...
zsolt2255
1

votes
1

answer
45

Views

Perl optional group in arbitrary place

I need to capture sereral groups and some of them are optional. I've read about optional in https://www.regular-expressions.info/optional.html but ? does not work for me. Example file: Code>123(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)(.*?)
Alexei Martianov
1

votes
1

answer
12

Views

How to assign a combination of string and a variable to another variable?

How can I assign a combination of string and a variable to another variable? For example, I need to prepare a piece of code that I need to write in a file based on the if condition match. Here $mod and $param are variables and rest of them is just plain text that I need to write in a file. $mode = '...
npatel
0

votes
0

answer
9

Views

What does -0777 means in Perl?

I know that perl -0777 -pi -e 's/foo\nbar\n//g' would slurp the entire file and would be equivalent to perl -pie -e 'BEGIN { local $/; } s/foo\nbar\n//g' Unfortunately I do not understand that -0777 means. The octal character 777 would be U+01FF or ǿ. I do not understand how ǿ could be linked to...
nowox
1

votes
1

answer
1.5k

Views

Replacing mutiple strings recursively within all files in a directory using Perl

I'm new with perl. saw many samples but had problems composing a solution I have a list of strings which each string should be replaced in a different string a->a2, b->b34, etc. list of replacement is in some csv file. need to perform this replacement recursively on all files in directory. might be...
user271077
0

votes
2

answer
48

Views

How to remove entire array that have specific character

I have a perl code that extract from .xls file. My .xls file is as below NUMBER NAME ALPHABET one Jane a two Adam b three Josh c ;four five Agnes e six Mary f ;seven eight Lara h I want to extract the info and...
daffodil
1

votes
0

answer
5

Views

Require Perl Modules using an Aliased Name

***The following is background to help explain what I've tried so far. If you'd prefer to read the main question first, skip to the bottom.*** Starting Out My Baz module invokes a number of other modules, all similar, each of which is one level down in the namespace. The ones of interest to me compo...
BryKKan
0

votes
0

answer
11

Views

Perl REST::Client - Garbage data in response

I'm having issues getting a valid response from Perl REST::Client against Red Hat Satellite REST API. I'm getting the following encoded response: $VAR1 = '���j�0��~ �g9�� ���#�9�`dIm�m�-���uJ �����f4U�@▒�� ���F��xګ X�;�\'r�...
Mose
1

votes
3

answer
1.4k

Views

Installing Perl module in Unix

This is my first time installing a Perl module and I'm having some trouble. I'm trying to install manually In UNIX. These are the steps I am following (Installing DBI module in this case) Download DBI-1.628.tar.gz tar file, Uncompress file with $ tar -zxvf DBI-1.628.tar.gz So far no problems, Its t...
BryanK
1

votes
3

answer
132

Views

k/Column number in Perl

So I'm sure this is somewhere on the site, but as always, I have looked high and low before asking a question. In Bash, you can use certain flags on some commands (such as k[number] on sort) to grab a certain column from a text file. What is the method for doing this in Perl? For an example from my...
Reubens4Dinner
11

votes
5

answer
133

Views

Can a Perl program know the line number where __DATA__ begins?

Is there a way to get the line number (and maybe filename) where a __DATA__ token was coded? Or some other way to know the actual line number in the original source file where a line of data read from the DATA filehandle came from? Note that $. counts from 1 when reading from the DATA filehandle....
jimav
1

votes
2

answer
67

Views

Why does this regexp not match?

my $genlog_line_1= qr{ \A (?:(\d{6}\s+\d{1,2}:\d\d:\d\d|\d{4}-\d{1,2}-\d{1,2}T\d\d:\d\d:\d\d\.\d+(?:Z|-?\d\d:\d\d)?))? # Timestamp \s+ (?:\s*(\d+)) # Thread ID \s (\w+) # Command \s+ (.*) # Argument \Z }xs; my $line = '2018-1...
wayuki
1

votes
2

answer
53

Views

find and replace numbers to LaTeX fractions correctly

My Perl script takes in data and stores it as an array. The script then takes this data and converts it into a code which I can then copy into LaTeX. Part of my data includes numbers such as 4.25, 6.5, 6.75, and I wish to do a find and replace, so that 4.25 is written as 4 1/4 when pasted into LaTeX...
C. de Haer
1

votes
2

answer
72

Views

Is it possible for Perl move success with response 0?

Every function in the perl File::Copy module is supposed to return 1 in case of success and 0 in case of failure. In my case, I have noticed (using whatever logs I had) that move returns 0 even when the operation succeeds (because files are actually moved) with value of $! as No such file or directo...
andor
1

votes
1

answer
75

Views

get request in perl and Use of uninitialized value

my $url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=journal+of+medical+virology[journal]+AND+2014[Date+-+Publication]:3000[Date+-+Publication]&usehistory=y'; print '\n before url \n'; print $url; #post the esearch URL my $output = get($url); print $output; I have not...
Simran kaur
1

votes
2

answer
49

Views

How to sort array values nested inside a hash with different keys?

I have an html table showing outage start and end times with different types of outages. Currently, I am sorting the outages in order of outage type, but I would like to be able to sort them by earliest to latest start times. The times in each start and end will already be in order, but I am trying...
knxwledge
1

votes
1

answer
51

Views

What are allowed symbols for naming perl5 modules and subroutines?

Is it [A-Za-z] and :: for module names and [A-Za-z_-] for subroutine names ? P.S. I'm writing regex for parsing some debug output.
Paul Serikov
1

votes
4

answer
95

Views

Pick up the longest peptide using perl

I want to find out the longest possible protein sequence translated from cds in 6 forward and reverse frame. This is the example input format: >111 KKKKKKKMGFSOXLKPXLLLLLLLLLLLLLLLLLMJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJX >222 WWWMPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPMPPPPPXKKKKKK I would like to find out all th...
IrisChang
1

votes
2

answer
59

Views

Sending using Email::Simple with To/From in body text instead of headers

Currently we are using a print to send an html mail via a sendmail pipe, which works fine. $fh->open( q{|sendmail -f .......} ); This comes from a template which contains text like... From: Reply-to: Subject: etc Mine-Version: 1.o Content-Type: text/html $header, body => $body ); sendmail( $email,...
Ian
1

votes
1

answer
46

Views

How to make Perl's XML::Libxml serializer to use utf-8 encoding?

I'd like to serialize an xml with XML::LibXML, but it always converts utf-8 characters to html representations: I get á from 'á', etc... How can I make it use utf-8 instead? use strict; use XML::LibXML; use utf8; my $str = 'árvíztűrő tükörfúrógép'; my $dom = XML::LibXML->load_xml(string =...
lmocsi
1

votes
3

answer
80

Views

From grep to perl: inverse matching by perl

it is pretty long time that I don't program in perl and I need some push. I need to compare two lists in order to retain only the lines that are not matching. my first file looks like this: 1 pf1 er2 0,4 2 pf1 er3 0,56 3 pf1 er6 0,72365 4 er3 pf3 0,263 5 pf5 er2 0,28473 The second fi...
Gabelins
1

votes
1

answer
54

Views

Perl, Help understanding Class declaration code

I am creating a class, and I am trying to understand the following code sub new { my ($class, %ar) = @_; return bless \%ar, $class; } I am specifically looking at the code inside of the block. my($class, %ar) = @_; I know that %ar are the arguments passed to the class, but i do not understand what t...
impact
1

votes
2

answer
68

Views

Perl hash dereferencing

I am working through Intermediate Perl by brian d foy (2nd ed). I'm on the section dealing with references to hashes. I have run one of the scripts in Strawberry Perl and I'm not sure I'm getting the intended results. the script is: my %gilligan_info = ( name => 'Gilligan', hat => 'White',...
John D
1

votes
2

answer
35

Views

Validating phone number using perl

I want to validate phone number with following conditions: length should be 10 digits should start with 7 or 8 or 9 If it does not meet these requirements, we should fail the number. I have tried the following: print 'Enter phone number: \n'; $name=; chomp $name; if (length($name)==10 && $name==~...
Rajendra Urs
1

votes
2

answer
69

Views

Regular Expression Substitution with Conditional Replacement in Perl

My Perl skills are pretty rudimentary and I'm trying to convert dates in a data file loaded in a scalar variable to a four digit year using a regular expression substitution (among other things). I've got the following to work to add a 20 to all years. $data00 =~ s/^D(\d{2})\/(\d{2})\/(\d{2})\n/D$1\...
tanker
1

votes
1

answer
21

Views

Error IMAPClient with message_string() function

you have an idea on how to solve this problem that I met with the function message_string () of Mail::IMAPClient library, here is my code: #!/usr/bin/perl -w use strict; use warnings; use Mail::IMAPClient; use IO::Socket::SSL; # Create the object connexion with socket SSL + LOG ON my $imap = Mail::I...
Red_Developper
1

votes
1

answer
42

Views

Perl dynamic hash of hash errors

I am looping over a query and returning results. I am trying to add a hash to another hashes. But running into trouble. my %users_data; while($sth->fetch) { $mygroup => { 'fname' => $fname, 'lname' => $lname, 'address' => { 'street' => $street, 'city' => $city, }, 'id' => $uid, }, } how do I add th...
user3525290
1

votes
1

answer
59

Views

Printing Perl CSS and HTML

I'm using a bit of Perl, and at the end, I print HTML and CSS for stuff to appear on the page, but only the HTML appears, the CSS styling and JavaScript doesn't work. Here's my print code: print ' body { margin: 0; padding: 0; } #faqDiv { height: 450px; width:700; background-color: white; position:...
Stefan Codrin

View additional questions