[Solved] Regex , regular expression [closed]
Are you looking for s/x([0-9a-fA-F]{1,5})/ chr hex $1 /eg 3 solved Regex , regular expression [closed]
Are you looking for s/x([0-9a-fA-F]{1,5})/ chr hex $1 /eg 3 solved Regex , regular expression [closed]
Ok. The object constructor syntax you are using is a bit akward, I’d prefer my $obj = Stats->new(13,4,56,43,33); In Perl, new is not an ordinary keyword, but a simple sub, and should be used as such. The Foo->sub(@args) syntax is exactly equivalent to Foo::sub(‘Foo’, @args), and thus takes care of passing the correct class name … Read more
One thing you could do is extract all numbers, then use the second one: my $astring = “cool more 23423 random words of 1234 random other [wordssssssss] 23”; my @numbers = $astring =~ /[0-9]+/g; print “The second number is $numbers[1]\n”; 1 solved Take second of three numbers from a line in a file [closed]
perl -lane ‘splice @F, 2, 3; print “@F”‘ -l removes newlines from input and adds them to output -n reads the input line by line, running the code for each line -a splits each line on whitespace into the @F array splice removes three elements from @F starting with position 2 (numbering starts at 0) … Read more
Here is semi-working and working code. Semi-working $ cat x1.pl | so #!/usr/bin/env perl use strict; use warnings; my $a = “$192.168.1.1”; print “$a\n”; $a =~ s/\$//; print “$a\n”; $ perl x1.pl | so Use of uninitialized value $192 in concatenation (.) or string at x1.pl line 5. .168.1.1 .168.1.1 $ Working $ cat x2.pl … Read more
If your date formats are static, you have two easy options. Option 1 Strip out the day, month, and year from each date. Compare the two years. If the years are the same, compare the two months. If the months are the same, compare the two days. Option 2 Strip out the day, month, and … Read more
It sounds like you are trying to rewrite ls | more. Do you really need to do this? The program below opens the file temp.txt for writing. It then usesqx (the equivalent of backticks) to get the output from a command and write it to the file. The same file is then reopened for reading, … Read more
You can use substr() as an lvalue and start replacing the string from right side of it, my $string = ‘GATGCAGTTAGGCGTAGCAGAGTGAGACGACGACGATATTAGGACCCGGTAAGGCACAATATAGC’; my %coord_colors = ( 10 => “red”, 48 => “orange”, 60 => “purple”, ); substr($string,$_,0) = $coord_colors{$_} for sort { $b <=> $a } keys %coord_colors; print $string; output GATGCAGTTAredGGCGTAGCAGAGTGAGACGACGACGATATTAGGACCCGorangeGTAAGGCACAATpurpleATAGC using regex, $string =~ … Read more
Easy in perl perl -pe ‘s-(\d+.?\d*)-($1/1000)-ge’ file add tube 3033.303 2998.20695111 106.1801625 0.060325 6.22260621 y 0 0 0 add cube 3027.18924332 3032.17578955 114.50875 0.1689 6.17076909 y 0 0 0 0 solved Unit conversion from mm to m in text file with text and numbers
If you want to know if the result of dividing a $dividend by a $divisor is going to be a whole number or a number with a fractional portion, you can test that condition first: if (my $remainder = $dividend % $divisor) { print “$dividend cannot be divided evenly by $divisor.”, ” There is a … Read more