Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
I want 0 replacing '०' Unicode character. I am using a Perl script and trying the code given below.
my %table_digits =
(
'०' => '0'
'१' => '1', .....)
It's working fine with other Unicode characters. Those are being replaced by other numbers. But it is not able to replace '०' with 0. How it can be done?
See Unicode numeric value in Unicode::UCD:
use 5.010;
use utf8;
use open ':std', ':utf8';
use Unicode::UCD qw(num);
for my $digit (qw( ० १ २ ३ ४ ५ ६ ७ ८ ९ )) {
say "$digit==".num($digit);
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
This is my sample code
#!/usr/bin/perl
$file = SUN;
$file1 = abc.$file.cde
print "Value is : $file1\n"
I want Output like this abcSUNcde
What regular expression need for this.
As well ikegami said in his comment you are missing the semicolons at the end of the line (terminating the line or line should be ended).
#!/usr/bin/perl
$file = SUN;
$file1 = "abc${file}cde";
print "Value is : $file1\n";
This is will print abcSUNcde as an output of your code.
In case if you want to remove the special characters (what I understand except keyboarding characters)
$file2=~s/[^A-Za-z]//g;
Let try this and modify as well you can.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
How can I change the format of dates 12/23/02 to 23/12/2002 or 03/35/55 to 35/03/2055?
I can read the dates from text file but I can't change their format:
15/06/17 ====> 06/15/2017
Here's the example using DateTime::Format::Strptime:
UPDATE:
use DateTime::Format::Strptime;
my $str = '12/23/02';
my $parser = DateTime::Format::Strptime->new( pattern => '%m/%d/%y');
my $dt = $parser->parse_datetime( $str );
print $dt->strftime('%d/%m/%Y')
output:
23/12/2002
I think the Perl Module Time::Piece should work
use Time::Piece 'strptime';
my %date = strptime('%d/%m/%y', '15/06/17');
The date hash contains then the parsed date elements, $date{d}, $date{m}, and $date{y} which you can use to reformat the date.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What is the difference between sprintf and printf in Perl?
I'm really confused with those functions.
I know about printf. It is used for STDOUT, but I want know in depth of these functions.
sprintf just returns a formatted string, printf prints it to a filehandle.
printf HANDLE "%s", $arg
can (very redundantly) be written as
$formatted = sprintf "%s", $arg
print HANDLE $formatted
Of course, this specific example is most naturally written as
print HANDLE $arg
because the format string I used for an example is so trivial as to be useless.
Of course, HANDLE is optional, and defaults to STDOUT, although you can also change the default with select.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Suppose I have a sentence/paragraph:
This cat is very cute.
Here, "cute" is the 5th word in the sentence. If I know the index of the first letter of this word - in this case c, 17 - how can I find out the position of this word in the sentence?
Counting the number of spaces in the substring and then adding 1 to it would probably work.
#!/usr/bin/perl
use strict;
use warnings;
my $in = "This cat is very cute.";
my $sub = substr $in, 0, 17;
my $word_count = scalar(split " ", $sub) + 1;
print "$word_count\n";
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to take a given input, say , and run specific parsings over it and fill a hash with the outputs of those parsings. For example, I'd like this input:
"barcodedSamples": "{\"I-735\":{\"barcodes\":[\"IonXpress_001\"]},\"13055\":{\"barcodes\":[\"IonXpress_002\"]}}",
to be parsed (using a combination of grep and some more specific fiddling that I don't have a strong grasp on) into a table that lists the barcodes and sample names as follows:
barcode sample
IonXpress_001 I-735
IonXpress_002 13055
where "barcode" and "sample" are treated as keys. Another example is that I would like to grep to a line that starts:
"library": "hg19",
and map the value "hg19" (so, the string inside the second set of quotation marks, programmatically speaking) to an arbitrary key like "lib":
Library
hg19
The string closely resembles JSON, however requires some cleaning up to become valid JSON.
#!/usr/bin/perl
use strict;
use warnings FATAL => qw/all/;
use JSON;
use Data::Dumper;
my $json_string = '"barcodedSamples": "{\"I-735\":{\"barcodes\":[\"IonXpress_001\"]},\"13055\":{\"barcodes\":[\"IonXpress_002\"]}}"';
$json_string =~ s/\\//g; # remove escape backslashes.
$json_string =~ s/"\{/{/; # remove an invalid opening quote.
chop $json_string; # remove an invalid closing quote.
$json_string = '{' . $json_string . '}'; # wrap in curly braces.
my $json_object = JSON->new( );
my $perl_ref = $json_object->decode( $json_string );
print Dumper( $perl_ref );
That string you're parsing looks suspiciously like JSON. Why not just use the JSON module (which comes with newer Perls, but can be installed from CPAN for older ones) instead of writing your own parser?