develooper Front page | perl.beginners | Postings from May 2007

Re: Passing arguments to subroutine

Thread Previous | Thread Next
From:
eishbut@googlemail.com
Date:
May 31, 2007 16:14
Subject:
Re: Passing arguments to subroutine
Message ID:
1180618528.333366.111180@q66g2000hsg.googlegroups.com
On May 31, 9:27 am, almatir...@gmail.com (Alma) wrote:
> Hi All,
>
> I need to pass the result of prepare statement as an argument to the
> subroutine.
>
> sub abc()
> {
>         my $self= shift;
>         my($id,$title) = @_;
>         my $sth1= $databasehandle->prepare("select file_path from xyz
> where id='$id' and title like '$title'");
>         my $res = $sth1->execute();
>
>         my @row = $sth1->fetchrow_array;
>         print @row;
>
>         &deleteposter_file(@row);
>
> }
>
> #-----------------Deletes from the File system
>
> sub delete_file()
> {
>         my $self = shift;
>         my $file_path = @_;
>
> # extract the file name
> #       my @parts = split('\/',$file_path);
> #       my $file =$parts[$#parts];
> #       #unlink($file);
> #       if( -e "file" ) {
> #       system("rm $file_path");
>
>         unlink($file_path);
>
> }

Your split statement seems to be wrong. split uses a regex to match so
it should be:

split /\\/, $file_path;

I'd also suggest making sure you're in the correct directory to use
unlink.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About