473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help me understand the following two Subroutines

135 100+
Subroutines: set_asset & destination_filename:

Basically I'm looking at some existing code used to upload images/files, can you help me understand exactly what is happening:

Expand|Select|Wrap|Line Numbers
  1. sub set_asset {
  2.     my %arg = @_;
  3.     my $customer = $arg{customer};
  4.  
  5.     my $copied = copy(
  6.         $arg{filename},
  7.         $customer->path."/assets/".$arg{destination}
  8.     ) or die "Cannot copy $arg{filename}: $!\n";
  9.  
  10.     my ($number, @error);
  11.     if ($arg{destination} =~ /\.(jpg|gif|jpeg|png|bmp|swf)$/i) {
  12.         ($number, @error) = createThumbnail($arg{folder}, $customer);
  13.     }
  14.     return ($number, @error);
  15. }
  16.  
  17. sub destination_filename {
  18.     my $full_path = shift;
  19.     my @opParts = splitdir $full_path;
  20.  
  21.     my $filename = $opParts[-1];
  22.     $filename =~ tr/ /_/;
  23.  
  24.     return $filename;
  25. }
  26.  
Jun 4 '07 #1
1 995
miller
1,089 Expert 1GB
Greetings patel,

The hardest thing to recognize is that set_asset accepts parameters in key value pairs. In other words, as a hash. It would be called like this.

Expand|Select|Wrap|Line Numbers
  1. set_asset(
  2.     customer    => $customer,
  3.     filename    => $filename,
  4.     destination    => $destination,
  5.     folder        => $folder,
  6. );
  7.  
This is simply a nice way to call subroutines if you have more than 2 parameters. This way the order of the parameters does not actually matter.

What the subroutine does, I leave to you.

The destination_filename sub simply pulls the filename from a full filename path, translates any spaces to underscores, and returns the result.

- Miller
Jun 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: joe | last post by:
Hello: I am using IIS 5.0, ASP and VBScript. I am puzzled by recurrences of errors when I nest subroutines, and I'd like to know if there are rules for that which I don't know. Would functions...
0
by: tbatwork828 | last post by:
If you were like me trying to figure out how to launch context sensitive help topic by the context id, here is the link: http://weblogs.asp.net/kencox/archive/2004/09/12/228349.aspx and if...
5
by: Koen | last post by:
Hi all, I created a function that updates a certain status field. The status can be influenced by four different other fields. So, on the form where I edit these fields I call the function (see...
2
by: Susan Bricker | last post by:
Greetings. Before I begin, I have been stuck on this problem for about a 5 days, now. I have tried and just seem to be not getting anywhere. I know that the explanation is lengthy, but I am a...
2
by: | last post by:
Help! I'm new to c++, and am breaking my teeth on MS Visual C++ (bundled within Visual Studio .NET 2003). Am trying to link simple c++ code to fortran dlls created in Compaq Visual Fortran (v6.1)....
7
by: Satish | last post by:
Hi Friends I am little confused about the shadows keyword in VB.NET could anyone explain with an example about Shadows keyword Many thanks Satish
3
by: OpticTygre | last post by:
I have a class, ProcessFiles, with several subroutines it runs for each type of file I want to "process." First, I check directories for files. Then, based on the filenames of those I find in...
2
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I have been battling a problem for nearly a month with the FileSystemWatcher component. Basically, what I am trying to do it to monitor three...
10
by: liz0001 | last post by:
Hi, I need to access an .asp subroutine file from a subdomain. i.e. the website is at www.domain.com and I want to access the same subroutines on the subdomain mobile.domain.com. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.