In perl, parentheses are used for overriding precedence (as in most programming languages) as well as for creating lists. How can I tell if a particular pair of parens will be treated as a grouping construct or a one-element list?
For example, I'm pretty sure this is a scalar and not a one-element list: (1 + 1)
But what about more compl...
What is the easiest way to get a key with the highest value from a hash in Perl?
...
I am learning Perl in a "head-first" manner. I am absolutely a newbie in this language:
I am trying to have a debug_mode switch from CLI which can be used to control how my script works, by switching certain subroutines "on and off".
And below is what I've got so far:
#!/usr/bin/perl -s -w
# purpose : make subroutine execution option...
I use SCIM on Linux for Chinese and Japanese language input. Unfortunately, when I try to capture input using Perl's STDIN, the input is crazy. As roman characters are typed, SCIM tries to guess the correct final characters.
^H (backspace) codes are used to delete previously suggested chars on the command line. (As you type, SCIM tri...
If I open a file ( and specify an encoding directly ) :
open(my $file,"<:encoding(UTF-16)","some.file") || die "error $!\n";
while(<$file>) {
print "$_\n";
}
close($file);
I can read the file contents nicely. However, if I do:
use Encode;
open(my $file,"some.file") || die "error $!\n";
while(<$file>) {
print decode("UTF-16",...
At the moment, I'm writing these arrays by hand.
For example, the Miscellaneous Mathematical Symbols-A block has an entry in hash like this:
my %symbols = (
...
miscellaneous_mathematical_symbols_a => [(0x27C0..0x27CA), 0x27CC,
(0x27D0..0x27EF)],
...
)
The simpler, 'continuous' array
miscellaneous_mathematical_sy...
I need to take a file and find the first occurrence of a literal string pattern as a complete line of the file:
Acknowledgments:
And then I wish to create a new file from the line of match all the way to the end of the file.
I expect perl is a good way to do this, but I'm not much of a perl person, alternatively maybe sed is a good w...
Possible Duplicate:
Is it possible for a Perl subroutine to force its caller to return?
I want to write a subroutine which causes the caller to return under certain conditions. This is meant to be used as a shortcut for validating input to a function. What I have so far is:
sub needs($$) {
my ($condition, $message) = @_;
...
Here's the code I have:
use strict;
use warnings;
use Log::Log4perl qw(:easy);
Log::Log4perl->init({
level => $DEBUG
});
my $logger = Log::Log4perl->get_logger("my.logger");
my $appender = Log::Log4perl::Appender->new("Log::Log4perl::Appender::File",filename => "my.file");
$appender->layout(Log::Log4perl::Layout::SimpleLayout->new);
...
I have a header file like this:
/*
* APP 180-2 ALG-254/258/772 implementation
* Last update: 03/01/2006
* Issue date: 08/22/2004
*
* Copyright (C) 2006 Somebody's Name here
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following con...
I plan to add a better search feature to my site, so I thought that I would write it in C and use the CGI as a means to access it. But it seems that Perl is the most popular language when it comes to CGI-based stuff. Why is that? Wouldn't it be faster programmed in C or machine code?
What advantages, if any, are there to writing it in a...
I have text file looks like that:
float a[10] = {
7.100000e+000 ,
9.100000e+000 ,
2.100000e+000 ,
1.100000e+000 ,
8.200000e+000 ,
7.220000e+000 ,
7.220000e+000 ,
7.222000e+000 ,
1.120000e+000 ,
1.987600e+000
};
unsigned int col_ind[10] = {
1 ,
4 ,
3 ,
4 ,
5 ,
2 ,
3 ,
4 ,
1 ,
5
};
Now, I want to convert each array (float / unsigned int...
The following code is working sort of fine:
open( PIPE, '-|', 'ant' );
for( <PIPE> ) {
print;
}
However, it doesn't do what I want. Since the Ant build can take 5 minutes, I would like to see the output line by line.
Instead, I'm getting the entire input at the end of the process.
Looking at it with the Perl debugger, Perl waits ...
Hi,
I've a problem in making a PERL program for matching the words in two documents. Let's say there are documents A and B.
So I want to delete the words in document A that's not in the document B.
Example 1:
A: I eat pizza
B: She go to the market and eat pizza
result: eat pizza
example 2:
A: eat pizza
B: pizza eat
result:pizza
(...
I'm not too fluent with the perl XML libraries (actually, I really suck at understanding encoding in general), all I'm doing is taking a string that possibly has characters such as "à" and putting it in an XML file, but when I open the file, I get an encoding error at the line containing such a character.
So I just need a lightweight wa...
This is for debugging purpose. I've got a for loop that generates some output to Cygwin bash's CLI.
I know that I can redirect outputs to text files and use Perl or even just a normal text editor to inspect the values printed out for a particular iteration, just feel that a bit painful.
What I am now thinking is, to place a special sub...
In case of Java, we can get the path separator using
System.getProperty("path.separator");
Is there a similar way in Perl? All I want to do is to find a dir, immediate sub directory.
Say I am being given two arguments $a and $b; I am splitting the first one based on the path separator and joining it again except the last fragment and...
I have a script that has been running for over a year and now it is failing:
It is creating a command file:
open ( FTPFILE, ">get_list");
print FTPFILE "dir *.txt"\n";
print FTPFILE "quit\n";
close FTPFILE;
Then I run the system command:
$command = "ftp ".$Server." < get_list | grep \"\^-\" >new_list";
$code = system($command);
Th...
How can I sum (using Linux shell) numbers in a column? If possible, I don't want to use powerful tools like awk or perl. I want something like giveMeNumber | sum
...
I am currently documenting all of Perl 5's operators (see the perlopref GitHub project) and I have decided to include Perl 5's pseudo-operators as well. To me, a pseudo-operator in Perl is anything that looks like an operator, but is really more than one operator or a some other piece of syntax. I have documented the four I am familiar...