OT: PERL

Is there a recommended "PERL for Dummies" book? All I need it for is searching and replacing mixed text and numeric strings using a text editor (UltraEdit, editing PSpice libraries).

I have "Learning Perl" by Randal Schwartz, but it's way too deep into stuff I don't need.

I guess what I need is a "cookbook" if such exists.

Suggestions? ...Jim Thompson

-- | James E.Thompson, CTO | mens | | Analog Innovations, Inc. | et | | Analog/Mixed-Signal ASIC's and Discrete Systems | manus | | Phoenix, Arizona 85048 Skype: Contacts Only | | | Voice:(480)460-2350 Fax: Available upon request | Brass Rat | | E-mail Icon at

formatting link
| 1962 | I love to cook with wine. Sometimes I even put it in the food.

Reply to
Jim Thompson
Loading thread data ...

formatting link

What you obviously need is "Google For Dummies."

John

Reply to
John Larkin

That book didn't sell because nobody could find it :-)

--
Failure does not prove something is impossible, failure simply
indicates you are not using the right tools...
nico@nctdevpuntnl (punt=.)
--------------------------------------------------------------
Reply to
Nico Coesel

I found the Perl "dummies" book right away... I just wanted confirmation from PERL'ies ;-) ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Why buy anything

formatting link
?

Reply to
Fred Bloggs

The Perl tutorials are pretty good. I use Perl occassionally, and have never deeded anything beyond perldoc.perl.org.

--
My liberal friends think I'm a conservative kook.
My conservative friends think I'm a liberal kook.
Why am I not happy that they have found common ground?

Tim Wescott, Communications, Control, Circuits & Software
http://www.wescottdesign.com
Reply to
Tim Wescott

Just discovered the site myself. Found some nice tutorials on just the part I need, find and replace strings (where the strings are variable length and content of mixed text and numerics). Provoked this morning by a need to process some PSpice netlists into a format readable by Cadence Virtuoso. ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Of course real men use AWK for that. ;)

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal Consultant
ElectroOptical Innovations LLC
Optics, Electro-optics, Photonics, Analog Electronics

160 North State Road #203
Briarcliff Manor NY 10510
845-480-2058

hobbs at electrooptical dot net
http://electrooptical.net
Reply to
Phil Hobbs

I was going to say, linux has a lot of simpler solutions than going for a full blown Perl. Even SED can do a lot. Lex, yacc, lots of choices. IIRC Lex was Erik Schmidt's (google) contribution to the world of software.

My issue with Perl is it has a lot of cryptic shortcuts. Fine for experts, but it makes studying existing code difficult.

Reply to
miso

I'm catching on. I can do a find with (text rather than Perl to illustrate)...

space'multiple-characters-text-and-numbers'space

(Note the single quote marks)

I want to replace with...

space{multiple-characters-text-and-numbers}space

(Note curly brackets)

When I try it in UltraEdit I get the curly brackets alright, but between them is replaced with the Perl "equation", rather than the original "multiple-characters-text-and-numbers".

Is there a way to "capture" that, or is there another way to approach the problem? ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Thanks, Les, good lead! I'm using UltraEdit which has built-in regular expression support, Perl, Unix and their own flavor. I'll poke around for "regsub". ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

In Tcl, the thing to use is regsub. Is there a regsub equivalent in Perl? Googling a bit, it looks like regsub *came from* Perl.

In Tcl ( I haven't used Perl in decades) , it would be:

C:\tcl>type h.tcl set s { blorp 'This has single quotes and text 43' arpf }

puts $s regsub -all " '" $s " {" s regsub -all "' " $s "} " s

puts $s

C:\tcl>tclsh85 h.tcl blorp 'This has single quotes and text 43' arpf blorp {This has single quotes and text 43} arpf

C:\tcl>

-- Les Cargill

Reply to
Les Cargill

"regsub" is Tcl-specific :-( ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Thanks, I'll give that a whirl. ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

Drat! Maybe this will work ( I cannot test it; sorry )

formatting link

$string =~ s/regex/replacement/g;

So try $string =~ s/ '/ {/g;

followed by

$string =~ s/' /{ /g;

My Perl is too weak to know whether this is good or not.

-- Les Cargill

Reply to
Les Cargill

Here's a stand alone perl program (between the --- cut lines )to do what you want:

--- cut #! /usr/bin/perl

while() { if( m/^ '(.*)' $/o ) { print ' {'.$1.'} '."\n"; } else { print; } }

--- cut

Copy this to some_file.pl. Change the #! /usr/bin/perl to match your system's perl executable, set the execute permission and run:

some_file.pl input.txt > output.txt

On Windows, you might have to run:

perl some_file.pl input.txt > output.txt

This looks explicitly for lines with one space, a quote ('), any text, another (') and a final space. All other lines are dumped as-is.

--
Paul Hovnanian     mailto:Paul@Hovnanian.com
------------------------------------------------------------------
I like long walks, especially when they are taken by people
who annoy me.
Reply to
Paul Hovnanian P.E.

Try this: Find: \s'(\w+)'\s

The \s matches with any whitespace (space, tab), parentheses define a matching region which can be referred in the replace. You can define multiple match regions to swap things, for example.

Replace: \{\1\} The replacement string should have space character in the beginning and end.

--
Mikko OH2HVJ
Reply to
Mikko OH2HVJ

Thanks, Mikko! ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
I love to cook with wine.     Sometimes I even put it in the food.
Reply to
Jim Thompson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.