[30321] in Perl-Users-Digest
Perl-Users Digest, Issue: 1564 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 18:09:45 2008
Date: Wed, 21 May 2008 15:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 21 May 2008 Volume: 11 Number: 1564
Today's topics:
Re: finding & saving accented (unicode) chars with perl <jimsgibson@gmail.com>
Re: finding & saving accented (unicode) chars with perl <jcmmat@gmail.com>
Re: How to determine if a word has an extended characte <rvtol+news@isolution.nl>
How would I extract the URL name. <cdalten@gmail.com>
Re: How would I extract the URL name. <jurgenex@hotmail.com>
Re: How would I extract the URL name. <cdalten@gmail.com>
Re: How would I extract the URL name. <jimsgibson@gmail.com>
Re: How would I extract the URL name. <cdalten@gmail.com>
Re: import CSV files to Excel <slick.users@gmail.com>
Re: Out of memory! Yet ... <whynot@pozharski.name>
Re: Perl equivalent of htmlspecialchars() <rvtol+news@isolution.nl>
Re: Perl equivalent of htmlspecialchars() <smallpond@juno.com>
running shell command without echo in terminal <anand.acharya@gmail.com>
Re: running shell command without echo in terminal <jimsgibson@gmail.com>
Re: running shell command without echo in terminal <ben@morrow.me.uk>
Re: running shell command without echo in terminal <anand.acharya@gmail.com>
stripping off part of the string <anand.acharya@gmail.com>
Re: stripping off part of the string <smallpond@juno.com>
Re: stripping off part of the string <ben@morrow.me.uk>
Re: stripping off part of the string <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 May 2008 12:36:08 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: finding & saving accented (unicode) chars with perl 5.6.1
Message-Id: <210520081236082210%jimsgibson@gmail.com>
In article
<e94b4949-5249-4bfe-842f-e426d7f24790@z72g2000hsb.googlegroups.com>,
<"jcmmat@gmail.com"> wrote:
> Hello fellow perl addicts,
>
> I have following issue :
>
> I want to find words containing accented chars,
> based on a simple regex having a placeholder for the accented chars
>
> I read everywhere that perl internally is fully unicode, so this
> should be no problem
> however my query doesn't work
>
> setup :
> given a list of words with '?' symbols (the chars to look for in a ref
> list) "@AllQstLines" &
> a reference list of correct accented words "@AllRefLines"
>
> #### Begin code
> foreach $wrd (@AllQstLines)
> {
> # Bir?ebbuga <----- example of a $qst
> next if ($wrd !~ /\?/); # skip if no unknow/illegal chars
> next if ($WrdSeen{$wrd});# skip if allready in replace list
> $WrdSeen{$wrd}=1;
> $wrd =~ s/\?/\./g; chomp($wrd);
> $found=0;
>
> @Matches=grep /$wrd/, @AllRefLines;
> foreach $match (@Matches)
> {
> $match =~ /$wrd/; $correct= $&;
> print "DBG: $wrd, $correct\n";
> $Correction{$wrd}=$correct;
> $found=1;
> last if ($found); ## only consider first match
> }
> if (!$found) {print "DBG: $wrd, NOTHING FOUND\n";}
> }
> #### End code
>
> The problem : in this way the ?ejtun never matches the reference
> "?ejtun"
> neither does Lu?ija seem to match "Lu?ija"
>
> what am I doing wrong ?
Several things:
1. You are using Perl 5.6. Unicode support exists in 5.6, but is not
recommended. From perluniintro:
"Perl's Unicode Support
Starting from Perl 5.6.0, Perl has had the capacity to handle Unicode
natively. Perl 5.8.0, however, is the first recommended release for
serious Unicode work. The maintenance release 5.6.1 fixed many of the
problems of the initial Unicode implementation, but for example regular
expressions still do not work with Unicode in 5.6.1."
2. You have not provided a complete, working program that someone can
run. We can only guess at what data you are using to test your program.
Unicode support by newsreaders is variable, so I am not sure if you are
using actual '?' characters in your post or they are something else and
my newsreader is rendering them as '?'.
3. You are using Google Groups to post. Many of the most knowledgeable
people reading this newsgroup filter out posts from Google. If you are
serious about using Usenet for help, you should get yourself a real
news reader and news provided. (By posting your entire article, I am
providing those who don't read posts from Google the opportunity to
read yours.)
If you wish to read more about Perl's unicode support, read perlunitut,
perlunicode, and perluniintro, available with your Perl distribution or
at <http://www.cpan.org>.
Good luck!
--
Jim Gibson
------------------------------
Date: Wed, 21 May 2008 13:41:29 -0700 (PDT)
From: "jcmmat@gmail.com" <jcmmat@gmail.com>
Subject: Re: finding & saving accented (unicode) chars with perl 5.6.1
Message-Id: <320d2308-cfe5-4bcc-b6a4-8e21666fe2aa@d1g2000hsg.googlegroups.com>
On May 21, 9:36 pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <e94b4949-5249-4bfe-842f-e426d7f24...@z72g2000hsb.googlegroups.com>,
>
>
>
> <"jcm...@gmail.com"> wrote:
> > Hello fellow perl addicts,
>
> > I have following issue :
>
> > I want to find words containing accented chars,
> > based on a simple regex having a placeholder for the accented chars
>
> > I read everywhere that perl internally is fully unicode, so this
> > should be no problem
> > however my query doesn't work
>
> > setup :
> > given a list of words with '?' symbols (the chars to look for in a ref
> > list) "@AllQstLines" &
> > a reference list of correct accented words "@AllRefLines"
>
> > #### Begin code
> > foreach $wrd (@AllQstLines)
> > {
> > # Bir?ebbuga <----- example of a $qst
> > next if ($wrd !~ /\?/); # skip if no unknow/illegal chars
> > next if ($WrdSeen{$wrd});# skip if allready in replace list
> > $WrdSeen{$wrd}=1;
> > $wrd =~ s/\?/\./g; chomp($wrd);
> > $found=0;
>
> > @Matches=grep /$wrd/, @AllRefLines;
> > foreach $match (@Matches)
> > {
> > $match =~ /$wrd/; $correct= $&;
> > print "DBG: $wrd, $correct\n";
> > $Correction{$wrd}=$correct;
> > $found=1;
> > last if ($found); ## only consider first match
> > }
> > if (!$found) {print "DBG: $wrd, NOTHING FOUND\n";}
> > }
> > #### End code
>
> > The problem : in this way the ?ejtun never matches the reference
> > "?ejtun"
> > neither does Lu?ija seem to match "Lu?ija"
>
> > what am I doing wrong ?
>
> Several things:
>
> 1. You are using Perl 5.6. Unicode support exists in 5.6, but is not
> recommended. From perluniintro:
>
> "Perl's Unicode Support
> Starting from Perl 5.6.0, Perl has had the capacity to handle Unicode
> natively. Perl 5.8.0, however, is the first recommended release for
> serious Unicode work. The maintenance release 5.6.1 fixed many of the
> problems of the initial Unicode implementation, but for example regular
> expressions still do not work with Unicode in 5.6.1."
>
> 2. You have not provided a complete, working program that someone can
> run. We can only guess at what data you are using to test your program.
> Unicode support by newsreaders is variable, so I am not sure if you are
> using actual '?' characters in your post or they are something else and
> my newsreader is rendering them as '?'.
>
> 3. You are using Google Groups to post. Many of the most knowledgeable
> people reading this newsgroup filter out posts from Google. If you are
> serious about using Usenet for help, you should get yourself a real
> news reader and news provided. (By posting your entire article, I am
> providing those who don't read posts from Google the opportunity to
> read yours.)
>
> If you wish to read more about Perl's unicode support, read perlunitut,
> perlunicode, and perluniintro, available with your Perl distribution or
> at <http://www.cpan.org>.
>
> Good luck!
>
> --
> Jim Gibson
Hello Jim & thx for your reaction
Google & newsreaders exactly show my code (but indeed changed the
lookds of the examples of reference text) :
i am using the Questionmark symbol as placeholder in my QstnLines &
thus the var $wrd
iow $wrd = Lu?ija (a qstn-mark as 3rd char)
the referenceLines & thus the var $match contains the real life &
correctly written word containing accented chars
iow $match = Luċija (3rd char = c-with-dot-above ; total word
looks like Lucija but with a different c)
so rephrased, the PERL problem seems to be that the statement
$match =~ /$wrd/
Luċija =~ /Lu?ija/
doesn't seem to be TRUE
what the total progrm wants to achieve, is find the real/correct
written word in a reference file,
given a list of 'simplified' keywords that do not contain any accented
chars, those are all replaced by a Questionmark
rgds
jc
------------------------------
Date: Wed, 21 May 2008 21:05:51 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: How to determine if a word has an extended character?
Message-Id: <g122rk.16k.1@news.isolution.nl>
ambarish.mitra@gmail.com schreef:
> I have a file which contains just one word. My task is just to find
> out if the word has any extended character. Thats all.
Define "extended character". Any character sorted after "\x7F" maybe?
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 21 May 2008 11:23:11 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: How would I extract the URL name.
Message-Id: <cb9d4979-55f2-4a0c-8c60-b712e9b78851@g16g2000pri.googlegroups.com>
Say I have an HTML document that contains the following...
<a href="/stuff.html">A Link</a>
How would I parse it so that if the program so "A Link", it would
fetch the corresponding URL?
------------------------------
Date: Wed, 21 May 2008 18:32:16 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How would I extract the URL name.
Message-Id: <rjq83415ahl5ac3irfbt5gsbvfcvfcjv26@4ax.com>
grocery_stocker <cdalten@gmail.com> wrote:
>Say I have an HTML document that contains the following...
>
><a href="/stuff.html">A Link</a>
>
>How would I parse it so that if the program so "A Link", it would
>fetch the corresponding URL?
Most people would use an appropriate HTML parser, e.g. HTML:Parser or
one of its relatives.
jue
------------------------------
Date: Wed, 21 May 2008 12:38:27 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: How would I extract the URL name.
Message-Id: <8bda0261-258a-4415-ab77-4ca01981cb08@p25g2000pri.googlegroups.com>
On May 21, 11:32 am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> grocery_stocker <cdal...@gmail.com> wrote:
> >Say I have an HTML document that contains the following...
>
> ><a href=3D"/stuff.html">A Link</a>
>
> >How would I parse it so that if the program so "A Link", it would
> >fetch the corresponding URL?
>
> Most people would use an appropriate HTML parser, e.g. HTML:Parser or
> one of its relatives.
>
> jue
At the risk of sounding dense, could you or someone provide a sample
snippet?
------------------------------
Date: Wed, 21 May 2008 13:00:01 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: How would I extract the URL name.
Message-Id: <210520081300010000%jimsgibson@gmail.com>
In article
<8bda0261-258a-4415-ab77-4ca01981cb08@p25g2000pri.googlegroups.com>,
grocery_stocker <cdalten@gmail.com> wrote:
> On May 21, 11:32 am, Jürgen Exner <jurge...@hotmail.com> wrote:
> > grocery_stocker <cdal...@gmail.com> wrote:
> > >Say I have an HTML document that contains the following...
> >
> > ><a href="/stuff.html">A Link</a>
> >
> > >How would I parse it so that if the program so "A Link", it would
> > >fetch the corresponding URL?
> >
> > Most people would use an appropriate HTML parser, e.g. HTML:Parser or
> > one of its relatives.
> >
> > jue
>
> At the risk of sounding dense, could you or someone provide a sample
> snippet?
There are numerous snippets in the documentation for HTML::Parser. I
would also look at the HTML::LinkExtor module.
perldoc HTML::Parser
perldoc HTML::LinkExtor
--
Jim Gibson
------------------------------
Date: Wed, 21 May 2008 14:57:35 -0700 (PDT)
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: How would I extract the URL name.
Message-Id: <69a936eb-8d1d-491b-bff4-dd785646a2c8@h1g2000prh.googlegroups.com>
On May 21, 1:00 pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <8bda0261-258a-4415-ab77-4ca01981c...@p25g2000pri.googlegroups.com>,
>
>
>
> grocery_stocker <cdal...@gmail.com> wrote:
> > On May 21, 11:32 am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> > > grocery_stocker <cdal...@gmail.com> wrote:
> > > >Say I have an HTML document that contains the following...
>
> > > ><a href=3D"/stuff.html">A Link</a>
>
> > > >How would I parse it so that if the program so "A Link", it would
> > > >fetch the corresponding URL?
>
> > > Most people would use an appropriate HTML parser, e.g. HTML:Parser or
> > > one of its relatives.
>
> > > jue
>
> > At the risk of sounding dense, could you or someone provide a sample
> > snippet?
>
> There are numerous snippets in the documentation for HTML::Parser. I
> would also look at the HTML::LinkExtor module.
>
> perldoc HTML::Parser
> perldoc HTML::LinkExtor
>
> --
> Jim Gibson
Eerr.....It looks like all those examples deal with manipulating the
tags itself. Ie, the <a></a> and <img>/</img>. I didnt see anything
that would deal with associating the text "A Link" with the url "/
stuff.html".
<a href=3D"/stuff.html">A Link</a>
------------------------------
Date: Wed, 21 May 2008 13:32:11 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: import CSV files to Excel
Message-Id: <fcecd759-f7f4-4f5b-a741-2cd2a1fe3434@k30g2000hse.googlegroups.com>
With 1868 CSV files and this is how long it took to execute the
script.
Wed May 21 10:48:51 2008 START
Wed May 21 12:30:59 2008 END
I found this link, http://www.rondebruin.nl/txtcsv.htm.
Now I have to learn VB and understand what it's doing.
I also look at Insert>Object>from files, but this is embedded only. I
can't interact between worksheet with hyperlinks.
Any help would be great.
Source Code:
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
print localtime() ." START \n";
my $localTime = localtime();
$localTime =~ s/\s/_/g;
$localTime =~ s/\:/_/g;
my $csv_path = "C:/slickuser/Tue_May_20_20_49_44_2008/*.csv";
my $fileOutput = "C:/slickuser/out.xls";
my $MAX_ROW = 65356;
my @csvFile = glob($csv_path);
my ($Excel,$Workbook,$Workbook_CSV,$CurrentSheet);
$Excel = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't
create Excel object \n";
$Excel->{'Visible'} = 0; #0 is hidden, 1 is visible
$Excel->{DisplayAlerts}= 0; #0 is hide alerts
$Excel->{SheetsInNewWorkbook} = 0;
$Workbook = $Excel->Workbooks->Add();
$Workbook->SaveAs($fileOutput) or die "Can't save file.\n";
foreach my $filename (sort(@csvFile))
{
$filename =~ s/\\/\//g;
my @tempFile = split(/\//,$filename);
my @sheetName = split(/\./,$tempFile[scalar(@tempFile)-1]);
#$Workbook = $Excel->Workbooks->Open($fileOutput);
$Workbook_CSV = $Excel->Workbooks->Open($filename);
$Workbook_CSV->ActiveSheet->Range("A1:Z$MAX_ROW")->Copy;
$Workbook->Worksheets->Add( {after => $Workbook-
>Worksheets($Workbook->Worksheets->{count})} );
$CurrentSheet = $Workbook->ActiveSheet;
$CurrentSheet->{Name} = $sheetName[0];
$Workbook->ActiveSheet->Paste();
#$Excel->ActiveWorkbook->Save();
$Workbook->Save();
$Workbook_CSV->Close();
}
$Workbook->Close();
$Excel->Quit();
Win32::OLE->FreeUnusedLibraries();
print localtime() ." END \n";
On May 21, 12:16 am, Ben Bullock <benkasminbull...@gmail.com> wrote:
> On Tue, 20 May 2008 22:28:45 -0700, Slickuser wrote:
> > $Excel = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't
> > create Excel object \n";
> > $Excel->{'Visible'} = 0; #0 is hidden, 1 is visible
> > $Excel->{DisplayAlerts}= 0; #0 is hide alerts
>
> It's probably better not to do this until the program is debugged. If you
> start the Excel process as invisible, then if something goes wrong you are
> left with lots of Excel processes running in the background.
>
> > $Excel->{SheetsInNewWorkbook} = 0;
>
> > $CSV = Win32::OLE->new('Excel.Application', 'Quit') || die "Can't
> > create Excel object \n";
>
> Why do you need to start two Excel processes? This seems crazy to me. You
> should use the same Excel process. Also you should usually check if Excel
> is already running and attach to the running process via
> Win32::OLE->GetActiveObject.
>
> > $CSV->{'Visible'} = 0; #0 is hidden, 1 is visible
> > $CSV->{DisplayAlerts}= 0; #0 is hide alerts
>
> > $Workbook = $Excel->Workbooks->Add();
> > $Workbook->SaveAs($fileOutput) or die $!;
>
> This $! is a mistake. If SaveAs fails, the error message won't be in $!,
> which probably contains a blank string. Instead it will available
> via Win32::OLE->LastError(). So you should say
>
> die Win32::OLE->LastError();
>
> > foreach my $filename (sort(@csvFile))
> > {
> > $filename =~ s/\\/\//g;
> > my @tempFile = split(/\//,$filename);
> > my @sheetName = split(/\./,$tempFile[scalar(@tempFile)-1]);
>
> It's a bit of a mess.
>
> > $CSV_WB = $CSV->Workbooks->Open($filename);
> > $CSV_WB->ActiveSheet->Range("A1:Z$MAX_ROW")->Select;
> > $CSV_WB->Copy;
> > $Workbook->Worksheets->Add( {after => $Workbook
> > ->Worksheets($Workbook->Worksheets->{count})} );
> > $CurrentSheet = $Workbook->ActiveSheet;
> > $CurrentSheet->{Name} = $sheetName[0];
>
> You can get the same result with
>
> if ($filename =~ /\\([^\\]*)\..*?$/) {
> $CurrentSheet->{Name} = $1;} else {
>
> print "Bad file name $filename.\n";
> # skip this name.
>
> }
>
> or you can use a CPAN module such as File::BaseName.
>
> > $Workbook->ActiveSheet->Paste();
>
> Assuming this works (I haven't tested it), what you're doing is taking
> data from one Excel process and putting it into another Excel process via
> a Perl process, which probably explains why it's slow. Win32::OLE basically
> is slow, and so it's better to not do things like this. You should start
> just one Excel process and automate the transfer of data between different
> workbooks using Perl.
------------------------------
Date: Wed, 21 May 2008 21:13:12 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Out of memory! Yet ...
Message-Id: <oa5eg5xkbo.ln2@orphan.zombinet>
alexxx.magni@gmail.com <alexxx.magni@gmail.com> wrote:
*SKIP*
> { for $x(1..$nx) { $AAA[$i][$x][$y]=$a[3+$nx*($y-1)+$x] } }
^^^^^^^^^^^^^^^----vvvv
> print("\n$i>\ttotal size: ",total_size($AAA));
Someone believes, that you don't C<use strict>.
*SKIP*
> BTW, as you can see I try to use Devel::Size to check how big becomes
> $AAA, but it always answers "12". WTF? I could accept it if it was
> "42", but "12", come on...
Because you move it to C<@AAA> but C<@$AAA>. The latter one you pass to
C<total_size>, filtered image is in C<@AAA>.
> thanks for any info....
C<perldoc perlintro> is eager to be read.
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Wed, 21 May 2008 21:12:11 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <g123eg.co.1@news.isolution.nl>
Ben Bullock schreef:
> stripslashes seems to be something like
>
> s/\\//g;
>
> in Perl.
I find it funny that it removes backslashes and not is called
stripbackslashes.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Wed, 21 May 2008 16:15:13 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <83e1a$483482f3$19261@news.teranews.com>
Dr.Ruud wrote:
> Ben Bullock schreef:
>
>
>>stripslashes seems to be something like
>>
>>s/\\//g;
>>
>>in Perl.
>
>
> I find it funny that it removes backslashes and not is called
> stripbackslashes.
>
The name in perlop is "leaning toothpick syndrome".
--S
** Posted from http://www.teranews.com **
------------------------------
Date: Wed, 21 May 2008 12:50:06 -0700 (PDT)
From: Anand <anand.acharya@gmail.com>
Subject: running shell command without echo in terminal
Message-Id: <0f037916-5971-4862-91c2-765dad1ed55c@a9g2000prl.googlegroups.com>
I want to run unix shell commands through perl script but I do not
want to echo the output of these commands on the terminal.
Is there a way in per function I can achieve this?
thanks,
Anand.
------------------------------
Date: Wed, 21 May 2008 13:08:53 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: running shell command without echo in terminal
Message-Id: <210520081308531866%jimsgibson@gmail.com>
In article
<0f037916-5971-4862-91c2-765dad1ed55c@a9g2000prl.googlegroups.com>,
Anand <anand.acharya@gmail.com> wrote:
> I want to run unix shell commands through perl script but I do not
> want to echo the output of these commands on the terminal.
> Is there a way in per function I can achieve this?
Sure. Either capture the output of the shell command by using the qx()
operator or, equivalently, backticks (`command`):
my $output = qx("command");
or by redirecting the output of the command to a file or the null
device:
system("command > /dev/null");
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Wed, 21 May 2008 21:15:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: running shell command without echo in terminal
Message-Id: <gfceg5-v7m1.ln1@osiris.mauzo.dyndns.org>
Quoth Anand <anand.acharya@gmail.com>:
> I want to run unix shell commands through perl script but I do not
> want to echo the output of these commands on the terminal.
> Is there a way in per function I can achieve this?
Do you mean simply
system "$command >/dev/null 2>/dev/null";
? For more complicated situations, and where you want to avoid having
the shell parse your command arguments, use IPC::Run.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Wed, 21 May 2008 14:50:47 -0700 (PDT)
From: Anand <anand.acharya@gmail.com>
Subject: Re: running shell command without echo in terminal
Message-Id: <41789311-aaff-4927-b0f6-3921626304cb@a32g2000prf.googlegroups.com>
On May 21, 1:15 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Anand <anand.acha...@gmail.com>:
>
> > I want to run unix shell commands through perl script but I do not
> > want to echo the output of these commands on the terminal.
> > Is there a way in per function I can achieve this?
>
> Do you mean simply
>
> system "$command >/dev/null 2>/dev/null";
>
> ? For more complicated situations, and where you want to avoid having
> the shell parse your command arguments, use IPC::Run.
>
> Ben
>
> --
> Musica Dei donum optimi, trahit homines, trahit deos. |
> Musica truces mollit animos, tristesque mentes erigit. | b...@morrow.me.uk
> Musica vel ipsas arbores et horridas movet feras. |
I directed the output to a log file. It also helped me debug.
Thanks for your replies.
thanks,
Anand.
------------------------------
Date: Wed, 21 May 2008 13:02:47 -0700 (PDT)
From: Anand <anand.acharya@gmail.com>
Subject: stripping off part of the string
Message-Id: <e4a98fa1-271e-4673-b193-a401c558ec8a@g16g2000pri.googlegroups.com>
I am running a perl script where I get the path of the current
directory with `pwd`. The path of my current directory is:
/usr/anand/scripts/test_scripts/src/ Now I want to remove the part
till scripts from this string. I'm only interested in ./test_scripts/
src/.
How can I achieve this?
Appreciate any help.
thanks,
Anand.
------------------------------
Date: Wed, 21 May 2008 16:30:04 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: stripping off part of the string
Message-Id: <79675$4834866f$21275@news.teranews.com>
Anand wrote:
> I am running a perl script where I get the path of the current
> directory with `pwd`. The path of my current directory is:
> /usr/anand/scripts/test_scripts/src/ Now I want to remove the part
> till scripts from this string. I'm only interested in ./test_scripts/
> src/.
> How can I achieve this?
> Appreciate any help.
>
> thanks,
> Anand.
Better would be:
use Cwd;
my $path = cwd();
$path =~ s/.*\/scripts/\./;
Note that neither `pwd` nor cwd() should be adding that last / on your path.
So you should get ./test_scripts/src
--S
** Posted from http://www.teranews.com **
------------------------------
Date: Wed, 21 May 2008 21:23:36 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: stripping off part of the string
Message-Id: <8vceg5-v7m1.ln1@osiris.mauzo.dyndns.org>
Quoth Anand <anand.acharya@gmail.com>:
> I am running a perl script where I get the path of the current
> directory with `pwd`. The path of my current directory is:
> /usr/anand/scripts/test_scripts/src/ Now I want to remove the part
> till scripts from this string. I'm only interested in ./test_scripts/
> src/.
How much do you know? For instance, do you always know it will be
'/usr/anand/scripts', or just that it will be some directory called
'scripts'?
There are several options. The correct way is to use File::Spec to split
the path into a list of directories, remove some from the start, and
then join them up again. Something like
use Cwd qw/cwd/;
use File::Spec::Functions qw/splitdir catdir curdir/;
my @dirs = splitdir cwd;
shift @dirs while @dirs and $dirs[0] ne 'scripts';
@dirs or die cwd . " isn't under a dir called 'scripts'";
$dirs[0] = curdir;
my $dir = catdir @dirs;
If you know the directory will be '/usr/anand/scripts' you can use
abs2rel instead:
use Cwd qw/cwd/;
use File::Spec::Functions qw/abs2rel/;
my $dir = abs2rel cwd, '/usr/anand/scripts';
Alternatively there's always the quick-n-dirty solution:
(my $dir = `pwd`) =~ s!.*/scripts/!./!;
Ben
--
Raise your hand if you're invulnerable.
[ben@morrow.me.uk]
------------------------------
Date: Wed, 21 May 2008 21:52:44 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: stripping off part of the string
Message-Id: <sleeg5-rkn1.ln1@osiris.mauzo.dyndns.org>
Quoth smallpond <smallpond@juno.com>:
>
> Better would be:
>
> use Cwd;
> my $path = cwd();
>
> $path =~ s/.*\/scripts/\./;
>
> Note that neither `pwd` nor cwd() should be adding that last / on your path.
> So you should get ./test_scripts/src
You do realise that (given that the OP was on Unix) Cwd just loads a
whole lot of stuff only to end up invoking `pwd`, don't you? :)
(There are good reasons to do it like this. Older systems that don't
have a getcwd syscall often have /bin/pwd installed setid, so that you
can find out your pwd even if you're in a directory you can't read.)
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1564
***************************************