Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl newbie..please help! 1

Status
Not open for further replies.

sacgirl

MIS
Nov 4, 2005
7
US
I want to form a path name so that I know where to save the file.

For example, this is taken from a sample XML file.

I want to take the words between each pair of single quotes, and concatenate and form a path.

So the output should be firstlevel\secondlevel\thirdlevel\filename

Can someone please help me?

<reportSearchPath>/content/package[@name='firstlevel']/folder[@name='secondlevel']/folder[@name='thirdleve']/report[@name='filename']</reportSearchPath>
 
#!/usr/bin/perl
$x = 'package[@name=\'firstlevel\']/folder[@name=\'secondlevel\']/folder[@name=\'thirdlevel\']/report[@name=\'filename\']</reportSearchPath>';

@y = ($x =~ /\'(\w+?)\'/g);
$y = join('\\', @y);
print "$y\n";
 
Awesome..this works great!!
So incredible sometimes to see how just 3 lines of codes in perl can do so much...I've heard great things about perl..but never really used it much at work, should kick myself for not learning..

Thank you so much aabiir!!
 
or trimmed down a bit:

Code:
$x = 'package[@name=\'firstlevel\']/folder[@name=\'secondlevel\']/folder[@name=\'thirdlevel\']/report[@name=\'filename\']</reportSearchPath>';
$y = join('/', ($x =~ /'([^']+)'/g));
print "$y\n";
 
unbelievable..2 lines of code...actually it's just one line coz I don't even need to print it out...

great job u guys!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top