w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » PERL » Page 1
Perl read and print Line by line
Please try this. while(<DATA>) { print $_, unless($_!~m/^$/ && $_!~m/My info/i && $. >= '10'); } __DATA__ My info info | info | info | ------------------------- 1 | 1 | 2 3 . . .

Categories : Perl

Perl one liner inside a perl script not working
Yes, use current perl process instead of forking new one. This is equivalent of your perl -pi -e 's/^(node.session.auth.authmethods*=s*).*$/#1hello/g' /root/text.conf one-liner, use strict; use warnings; local $^I = ""; local @ARGV = "/root/text.conf"; while (<>) { s/^(node.session.auth.authmethods*=s*).*$/#1hello/g; print; }

Categories : Perl

Perl, ne operator not working
Try using indentation so you can see when your blocks end at inappropriate places. if ($line ne $search) isn't even within the foreach loop where you are populating and handling $line from the file. I suggest putting it within the block to at least get the functionality I assume you are looking for.

Categories : Perl

How to redirect output from a Library's function in perl?
Check out Capture::Tiny use Capture::Tiny qw[ capture ]; ( $stdout, $stderr, @result) = capture { xxLib1xx::Function1($Arg1) };

Categories : Perl

Perl Sorting Character Strings
OK, I'm trying this: #!/usr/bin/perl use strict; use warnings; sub sort_vowelsonly { my $a_vowels = $a; my $b_vowels = $b; $a_vowels =~ s/[^aeiou]//g; $b_vowels =~ s/[^aeiou]//g; print "DEBUG: Comparing $a_vowels with $b_vowels "; return $a_vowels cmp $b_vowels } print sort { sort_vowelsonly } <DATA>; __DATA__ albatross apparate fanfare candelabra panacea vermeil pa

Categories : Perl

sed for weather for conky
Probably conky's config parser "eats" a lot of your special characters in the sed command. If really that's the problem, you could go for a sed interpreter script instead. Create the file /usr/local/bin/inxi2conky with the contents below and make it executable: #!/bin/sed -rf # Remove leading whitespace s/^[ ]+// # Insert linefeeds in front of keys s/Co|Wind|Hu|Pr|Loc|

Categories : Perl

Use of uninitialized value in concatenation (.) or string issue
You're receiving this warning because $bam_file is undefined, because either there is no file matching /home/Desktop/data/BWA_2/*SNP.bam, or you do not have permission to read that folder in the first place. If you wish to prevent that warning, you can do a few things: Change the string based on whether a file is found or not: my $bam_file = glob("$BWA_dir/*SNP.bam") || ''; # If glob returns und

Categories : Perl

"cannot open file" for perl under cygwin
And I am sure this code is tested, so it could be me doing something wrong, access right? or what else can it be? Verify that the perl invoked is indeed the Perl from CygWin. The error you are seeing makes only sense in case if you have, in addition to CygWin, also native Windows Perl installed. CygWin's Perl understands /cygdrive/ paths - native Windows Perl doesn't. To tell one from anot

Categories : Perl

What is the function of following Perl script?
It trims all spaces, then inserts spaces between each character, taking care to keep UTF-8 characters intact. vnix$ perl /tmp/tryme.pl <<<'play frëëbïrd' p l a y f r ë ë b ï r d

Categories : Perl

How can I use perl debuggers pretty print for a hash in normal program code?
Use Data::Dumper. It is a core module, so no installation required. It is a good debugging tool. use Data::Dumper; ... print Dumper \%my_hash;

Categories : Perl

concatenating hex numbers in perl
It seems you want to shift first number by four places left (* 0x10), and add second to it my $A=0x2; my $B=0x3; my $C = ($A <<4) +$B; printf("%x", $C); output 23

Categories : Perl

strange behavior of array declaration in perl
The reason is that when you declare @values at the begining it is the same array value. So you take a reference to the same array so each loop overwrites the previous declaration. However if you declare the array in the loop then at the wnd of each iteration the array falls out of scope amd no longer points to the value. Then during the next iteration, the array is redecared with a new value.

Categories : Perl

delete few lines below a pattern until a blank line is found using perl code
Since the substitution you are doing is depends on previous match, you can slurp the file and just change what is between HEADER1 and HEADER2: use strict; use warnings; use v5.18; my $old_file = do { local $/; <DATA> }; my $description1 = "Biren Kumar Stephen"; my $description2 = "rahul123@mail.com shael@mail.com"; my $new_data = $old_file =~ s/(.HEADER.*? ).*?( .HEADER.*? ).*/${1}${des

Categories : Perl

Why does Perl give this warning?
The function of and is to compare boolean truth values. An assignment in a boolean context is frequently an error (people write if $a=$b when they mean if $a==$b) so warnings issues a message for this. If you really genuinely want to print only if " " evaluates to true, you can use && instead of and; but from your example, the semicolon makes much more sense.

Categories : Perl

How to fix ActivePerl's PPM "database disk image is malformed" error?
Try updating your DBD::SQLite package directly from CPAN. Or, try telling PPM to upgrade everything. If those don't want to work, you may need to reinstall ActivePerl. HTH! TheJester1977

Categories : Perl

How to catch signal in Perl and don't stop process
What does the rest of you code look like? Because that should work fine, with one caveat (well two - you do potentially issue a 'die' within your handler). Kill will interrupt certain system calls, like 'sleep', and your code will jump past it. IGNORE works a little differently - your code will discard the signal without processing it.

Categories : Perl

What is the right regex to match a relative path to an image file?
If you don't care the path prefix, use: $path =~ /.(jpg|png)$/ or substr($path, -4) ~~ ['.jpg', '.png'] With exactly '../../', use: $path =~ m!^../../[^/]*.(jpg|png)$! With any number of '../'s, use: $path =~ m!^(../)*[^/]*.(jpg|png)$!

Categories : Perl

Overloading constants in Perl 6
I don't think anything like overload::constant exists in the spec or the existing libraries, but it should be possible to write it using macros by looking in the AST for the type of literal that you're interested in, and replacing it with an object constructor or whatever you need. Cleaner, perhaps, would be to wrap each one of these constants in a macro invocation, instead of spanning the whole

Categories : Perl

Undefined subroutines &main error in perl
In perl, if you use fasta;, this does not automatically export all its methods into the namespace of your program. Call fasta::read_fasta instead. Or: use Exporter to automatically export methods or enable something like use Fasta qw/read_fasta/. e.g.: package Fasta; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw/read_fasta read_seq read_seq40/; to use: use Fasta qw/read_fast

Categories : Perl

How to use Lingua::EN::Ngram for multiple files
Your code <$pos_file/*> should work fine ( thanks @borodir ), still, here is an alternative so as to not mess up the history. Try opendir (DIR, $directory) or die $!; and then while (my $filename = readdir(DIR)) { open ( my $fh, $filename ); # work with filehandle close $fh; } closedir DIR; If called in list context, readdir should give you a list of files: my @file

Categories : Perl

Wget changing character around download location
It's not wget changing the character. The character encoding seems to be set to something wrong. When the real encoding is UTF-8, as it probably is, but set to something else, showing the quote as character â is a typical symptom. Sometimes it's followed by more characters. So it should work if you set the encoding to UTF-8. -- What is the output of the command locale? Background info: http:

Categories : Perl

how do you validate server cert & each of the certificate in the chain up to the ROOT in perl - 4 levels deep
IO::Socket::SSL will do all the verification for you if you don't disable it by setting SSL_verify_mode to 0. It will also check if the certificate is revoked if you provide the necessary CRL (SSL_crl_file) or use OCSP by setting SSL_ocsp_mode and call $ssl->ocsp_resolver->resolve_blocking(). It does not provide an interface to do this steps by hand and neither does the underlying Net::SSLe

Categories : Perl

!= operator not working
The == and != operators compare the operands as numbers. The operators for string comparisons are eq and ne. Reference: http://perldoc.perl.org/perlop.html#Equality-Operators

Categories : Perl

Final piece of the puzzle required ( returning a value requested by the user)
You really should put a question in your question. I assume your code is not working. I know that the line $line =~ $value may very well not do what you want if $value contains special characters. have a look here ( Q E may be what you want ) IF that is the problem and you need to solve it.

Categories : Perl

Point perl at specific freeTDS library
Here is a link on how to specify what version of a module that you want to use: perldoc Is is essentially use module version; Here is a link to perlmonks where configuring freeTDS is discussed: perlmonks

Categories : Perl

Usage of Range operator in perl
Per http://perldoc.perl.org/perlop.html#Range-Operators: If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two. In all other regards, "..." behaves just like ".." does. So, this: /Work items:/ ... !/^s*(d+) (d+)/ means "from a line that matches /Work items:/ until the next subsequent line that doesn't match /^s*(d+)

Categories : Perl

Additional conditions in JOIN
I don't even know what Catalyst is but I can hack the SQL query: select articles.id, reads.user_id from articles left join ( select * from reads where user_id = 9 ) reads on articles.id = reads.article_id order by articles.last_update desc limit 5;

Categories : Perl

Examples from Net::RabbitMQ not working
It doesn't error out. It prints to STDERR without checking if an error occured. It says I'll try and then it does: $mq->connect( $qserver, %qparms ); This is just an information, not an error.

Categories : Perl

how loop trough list(perl) foreach?
the for loop seems fine. There is, however, a semicolon missing after the if, within the loop. $bla = print " $& ", if($Sngline=~m/^pc([^s]*)s/g); In perl, DO if (CONDITION); is ok for DO being one line, otherwise if ( ){} Furthermore, $bla seems to be undeclared as far as I can see here.

Categories : Perl

What is the difference between perl as a language and CGI scripts?
The relationship between Perl and CGI is often confused, mostly because they are frequently seen together. This occurs so often, in fact, that the term “Perl CGI” became commonplace. In reality, any number of programming languages can be used with the Common Gateway Interface. Additionally, Perl is run through cgi-bin, suggesting a relationship. If that wasnt enough, the file extension is usua

Categories : Perl

Add a space for every symbol matched from excel sheet with perl
you simply need to rewrite the line elsif ($cell =~ m/?/ ) into elsif ($cell->unformatted() =~ m/?/ ) Then you will get the correct result. With some test data from me (third row has ?) print join(' - ',@firstvalues), " "; 1 - 2 - - 4

Categories : Perl

how to use split? (using perl)
The first argument to split is a regular expression which should match something in the input. The input is split into fields around those matches. for my $line (split(/ /, $match) { @fields = split(/|/, $line); } would obtain the text between the | separators (you need to backslash it because a bare | is a regex metacharacter) inside the loop. You can trim the spaces around the values by o

Categories : Perl

Perl glob returning a false positive
Using glob (aka <filepattern>) in a scalar context makes it an iterator; it will return one file at a time each time it is called, and will not respond to changes in the pattern (e.g. a different $dir) until it has finished iterating over the initial results; I suspect this is causing the trouble you see. The easy answer is to always use it in list context, like so: if( -d $dir &&

Categories : Perl

perl - int() decrementing an integer
From perldoc: machine representations of floating-point numbers can sometimes produce counterintuitive results. For example, int(-6.725/0.025) produces -268 rather than the correct -269; that's because it's really more like -268.99999999999994315658 instead So, the machine representation of "15" is probably something like 14.9999999999999999 and, therefore, int truncates it to 14. Note that

Categories : Perl

Split File into chunks keeping complete lines in solaris
Here is a generic solution for you in awk awk '{a[NR]=$0} END {t=int (NR/s);r=((NR/s-t)*s);while (n<s) for (i=t*n+++1;i<=t*n;i++) print a[i] > "file"n;while (i++<=NR) print a[i-1] > "file"n}' s=3 infile This splits the infile to s numbers of file. If you set s=3 you get file1 file2 file3 The data that does not divide up, ends up in last file. Example cat number 1 one

Categories : Perl

get nbest key-value pairs hash table in Perl
The tidiest way to do this is to write a subroutine that returns the N most frequent translations for a given word. I have written best_n in the program below to do that. It uses rev_nsort_by from List::UtilsBy to do the sort succinctly. It isn't a core module, and so may well need to be installed. I have also used an executable substitution to modify the string in-place. use utf8; use strict; u

Categories : Perl

Warning not being sent to stderr
Precedence issue. warn "$a is negative" && return 0 means warn("$a is negative" && return 0) You want warn "$a is negative" and return 0 or warn("$a is negative") && return 0 Better yet, apply both changes. warn("$a is negative") and return 0 Be wary of pitfalls when you omit parens around argument lists. Generally, use and and or if the RHS expression consi

Categories : Perl

Use perl remove new lines from windows file in unix
You may prefer this refactoring of you program. use autodie saves manually checking the status of the open call use open sets the default mode of all standard and newly-opened IO handles The while loop is made more concise by using the default $_ to hold input lines There is a built-in line counter $. which you may as well use The executable substitution changes all trailing whitespace -- which

Categories : Perl

Get the output of a command executed via $self->send() on a remote host in Perl Expect module
I am by no means an expert on this but as noone else has answered so far, let me attempt it. Your expect command is the su and as such, normal expecting will only work on whatever that command answers back to your original shell. That however is only the password prompt and maybe some error messages. You can still send commands, but their responses show up on the shell of the new user, not the sh

Categories : Perl




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.