09-19-2013
Search and replace (perl)
How can I achieve this? Perl would be awesome.
Input string a_b c[10_9] //Note there is a blank here
Needed Output a_b_c[10:9]
Thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello all
im facing some kind of problem i have this string :
functionA() $" "$ functionB("arg1") $" = "$
i will like to replace all the pairs of opening and closing "$" to be something like that
functionA() <#" "#> functionB("arg1") <#" = "#>
i cant of course do is with simple ... (1 Reply)
Discussion started by: umen
1 Replies
2. Shell Programming and Scripting
Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
3. Shell Programming and Scripting
Hello,
I have a Perl script that reads in an Excel spread sheet and formats the values into a text file. I am having trouble with one column that can have numbers or letters. Excel left justifies the values that start with a letter and right justifies the values that contain only a... (2 Replies)
Discussion started by: jyoung
2 Replies
4. Shell Programming and Scripting
I have a file where the rows correspond to individuals and the columns are about 106 variables. Each variable is coded as either ACGT, and "missing" is coded as blank. This is a tab delimited file. I'm trying to replace all blanks (" ") with 0. The simple script I have is only replacing some of the... (3 Replies)
Discussion started by: epi8
3 Replies
5. Shell Programming and Scripting
Hi. I have a file with asterisk field separators and backslash line terminators. The first field in each line names the line type. I am trying to process each range separately. Here's what the data looks like:
BA*DATA\
LS*DATA1*DATA2*00020*\
TA*DATA1*DATA2*DATA3*\
TA*DATA1*DATA2*DATA3*\... (1 Reply)
Discussion started by: yoi2hot4ya
1 Replies
6. Shell Programming and Scripting
I am not sure if this is doable. I am trying to open and print the content of the file by replacing all instances fo perl to PERL . This is my code but it is
giving me the number count instead of the actual lines with changes.
open (PERLHISTORY, 'sample.txt') or die "The file sample.txt could... (3 Replies)
Discussion started by: jxh461
3 Replies
7. Shell Programming and Scripting
I am trying to write a simple perl script to run on a FreeBSD machine.
There are alot of posts here, and I have read so many, yet can not get this script to run.
#!/usr/bin/perl
-e 's/\r\n/~/' infile.txt outfile.txt
I am trying to take a windows text file, move it into Unix, run a script on... (1 Reply)
Discussion started by: mach1
1 Replies
8. Shell Programming and Scripting
Hi,
I have a file having around 30 records. Each record has 5 fields delimited by PIPE. Few records in the file having Junk characters in the field2 and field4.
I found the junk charcter and I tested it and replace the junk with space with the command below
perl -i -p -e "s/\x00/ /g"... (1 Reply)
Discussion started by: ramkrix
1 Replies
9. Shell Programming and Scripting
When I use special characters the command to replace multiple files with a string pattern does nt work.
---------- Post updated at 12:33 PM ---------- Previous update was at 11:38 AM ----------
This works
perl -pi -e 's/100/test/g' *
This does nt work
perl -pi -e 's... (1 Reply)
Discussion started by: w020637
1 Replies
10. UNIX for Advanced & Expert Users
Hi All,
i can replace a perticular value in sentence using perl.
perl -pi -e 's/old/new/' sample.txt
but i am not able to replace whole string by perl.
file1 contains "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.147.109.211)(PORT=1526))(CONNECT_DATA=(SID= MWDBD22)))". i... (3 Replies)
Discussion started by: arindam guha
3 Replies
LEARN ABOUT MOJAVE
data::dumper::concise::sugar
Data::Dumper::Concise::Sugar(3) User Contributed Perl Documentation Data::Dumper::Concise::Sugar(3)
NAME
Data::Dumper::Concise::Sugar - return Dwarn @return_value
SYNOPSIS
use Data::Dumper::Concise::Sugar;
return Dwarn some_call(...)
is equivalent to:
use Data::Dumper::Concise;
if (wantarray) {
my @return = some_call(...);
warn Dumper(@return);
return @return;
} else {
my $return = some_call(...);
warn Dumper($return);
return $return;
}
but shorter. If you need to force scalar context on the value,
use Data::Dumper::Concise::Sugar;
return DwarnS some_call(...)
is equivalent to:
use Data::Dumper::Concise;
my $return = some_call(...);
warn Dumper($return);
return $return;
If you need to force list context on the value,
use Data::Dumper::Concise::Sugar;
return DwarnL some_call(...)
is equivalent to:
use Data::Dumper::Concise;
my @return = some_call(...);
warn Dumper(@return);
return @return;
If you want to label your output, try DwarnN
use Data::Dumper::Concise::Sugar;
return DwarnN $foo
is equivalent to:
use Data::Dumper::Concise;
my @return = some_call(...);
warn '$foo => ' . Dumper(@return);
return @return;
If you want to output a reference returned by a method easily, try $Dwarn
$foo->bar->{baz}->$Dwarn
is equivalent to:
my $return = $foo->bar->{baz};
warn Dumper($return);
return $return;
If you want to format the output of your data structures, try DwarnF
my ($a, $c) = DwarnF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
is equivalent to:
my @return = ($awesome, $cheesy);
warn DumperF { "awesome: $_[0] not awesome: $_[1]" } $awesome, $cheesy;
return @return;
If you want to immediately die after outputting the data structure, every Dwarn subroutine has a paired Ddie version, so just replace the
warn with die. For example:
DdieL 'foo', { bar => 'baz' };
DESCRIPTION
use Data::Dumper::Concise::Sugar;
will import Dwarn, $Dwarn, DwarnL, DwarnN, and DwarnS into your namespace. Using Exporter, so see its docs for ways to make it do something
else.
Dwarn
sub Dwarn { return DwarnL(@_) if wantarray; DwarnS($_[0]) }
$Dwarn
$Dwarn = &Dwarn
$DwarnN
$DwarnN = &DwarnN
DwarnL
sub Dwarn { warn Data::Dumper::Concise::Dumper @_; @_ }
DwarnS
sub DwarnS ($) { warn Data::Dumper::Concise::Dumper $_[0]; $_[0] }
DwarnN
sub DwarnN { warn '$argname => ' . Data::Dumper::Concise::Dumper $_[0]; $_[0] }
Note: this requires Devel::ArgNames to be installed.
DwarnF
sub DwarnF (&@) { my $c = shift; warn &Data::Dumper::Concise::DumperF($c, @_); @_ }
TIPS AND TRICKS
global usage
Instead of always just doing:
use Data::Dumper::Concise::Sugar;
Dwarn ...
We tend to do:
perl -MData::Dumper::Concise::Sugar foo.pl
(and then in the perl code:)
::Dwarn ...
That way, if you leave them in and run without the "use Data::Dumper::Concise::Sugar" the program will fail to compile and you are less
likely to check it in by accident. Furthmore it allows that much less friction to add debug messages.
method chaining
One trick which is useful when doing method chaining is the following:
my $foo = Bar->new;
$foo->bar->baz->Data::Dumper::Concise::Sugar::DwarnS->biff;
which is the same as:
my $foo = Bar->new;
(DwarnS $foo->bar->baz)->biff;
SEE ALSO
You probably want Devel::Dwarn, it's the shorter name for this module.
perl v5.18.2 2013-12-31 Data::Dumper::Concise::Sugar(3)