473,240 Members | 1,621 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,240 software developers and data experts.

Appending the required string between the variable(concatenation) ?

Hi Everyone,

i need to add a string in between the filename.so that new file will have the
required filename.

what am doing is reading the files from the directory & extract only the filename and then pass this failename to create new file.

now what i need is instead of just passing filename, i need to add some string to this filename & then pass the filename to create a new file.

Expand|Select|Wrap|Line Numbers
  1. sub loadavg_file(){
  2. my $dir = 'C:\Performance_svap\INPUT_FILES\*.xls'; 
  3. my @file=glob("$dir"); 
  4. my @output;
  5. my $loadavg;
  6. my $str;
  7. my $str1;
  8. my @data;
  9. my $date;
  10. foreach my $f (@file){
  11.  $str = substr($f,32,39);
  12.  $str1 = substr($str,0,9);
  13.  $loadavg ="c:\\Performance_svap\\OUTPUT_FILES\\$str";
  14.  
  15. blaah blaah...
  16. ....
  17. ....
  18. }
  19. open(EX,">$loadavg") or die "Can't open open $loadavg:$!";
  20. print EX "$output[0]\t$output[1]\t$output[2]\t$output[3]\t$output[4]\n"; 
  21. close EX;
  22. }
  23.  
so, in the above script, $str variable holds the filename. now to this variable i need to append the required string in between ie,
Expand|Select|Wrap|Line Numbers
  1. $str will have = prstat-Ls-20080118-1800.xls value.
  2.  
now i need to append the string to this variable & it should look like
Expand|Select|Wrap|Line Numbers
  1. $str = prstat-Ls-LAVG-20080118-1800.xls
  2.  
i tried changing with first instance ie,
Expand|Select|Wrap|Line Numbers
  1. $str = substr($f,32,39);
  2. $str1 = substr($str,0,9);
  3. $str = "LAVG".$str;
  4. $loadavg ="c:\\Performance_svap\\OUTPUT_FILES\\$str";
  5.  
am not getting how append the string in between the file name.

any help or suggestions will great full for me.

Thanks,
Vijayarl
Oct 24 '08 #1
6 4428
You can use the period operator like this:

$str = $str1 . "LAVG" . $str;
Oct 24 '08 #2
hey thanks for reply !!! i try it right away !!!

but what i feel is what you have suggested will give this i guess :
Expand|Select|Wrap|Line Numbers
  1. $str1 = substr($str,0,9); # holds the value =prstat-Ls
  2.  
so i guess i will get this ouput from your logic
Expand|Select|Wrap|Line Numbers
  1. $str=prstat-Ls-LAVG-prstat-Ls-20080118-1800.xls
  2.  
anyway i will cm back !!!

Regards,
Vijayarl
Oct 24 '08 #3
hi scruff6119,

my guess was right... am getting output like this
Expand|Select|Wrap|Line Numbers
  1. prstat-Ls-LAVG-prstat-Ls-20080118-1800.xls
  2.  
i instead want the file name to look like this:
Expand|Select|Wrap|Line Numbers
  1. prstat-Ls-LAVG-20080118-1800.xls
  2.  
thanks for your reply

any help or idea ???

Regards,
Vijayarl
Oct 24 '08 #4
hi there,

i got it...it was simply..
Expand|Select|Wrap|Line Numbers
  1. foreach my $f (@file){
  2. $str = substr($f,32,39);
  3. $str1 = substr($str,0,9);
  4. $str2 = substr($str,10,27);
  5. $str = $str1 . "-LAVG-" . $str2;
  6. $loadavg ="c:\\Performance_svap\\OUTPUT_FILES\\$str";
  7. }
  8.  
Thanks you...

Regards,
Vijayarl
Oct 24 '08 #5
Could do it by regex too:

$str =~ s/(.*?Ls-)(\d{8}.*?\.xls)/$1LANG-$2/
Oct 24 '08 #6
hey thanks scruff6119 !!!!

Even this worked...As am not so good at regex.. i didn't thought of this idea..

anyway's thanks for you help :-)

Regards,
Vijayarl
Oct 24 '08 #7

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

Similar topics

6
by: Jonathan | last post by:
Why did the designers of PHP decide to use period (".") as the string concatenation operator rater than the obviously more logical plus ("+")? //JJ
7
by: Oliver Crow | last post by:
As a realtive python newb, but an old hack in general, I've been interested in the impact of having string objects (and other primitives) be immutable. It seems to me that string concatenation is...
5
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
1
by: Fahd Khan | last post by:
Hi team! While troubleshooting a crash I had while using BitTorrent where the torrent's target file names didn't fall into the ascii range I was playing around in the interpreter and noticed this...
23
by: Bonj | last post by:
what is the correct form of string concatenation in VB.NET, + or &? Both seem to work, but which is correct? I know it's + in C# and & in VB6, but which in VB.NET?
2
by: cgmoore | last post by:
Hi, I think I read somewhere that strVar = "one" & "andtwo" & "andthree" is the equivalent of strVar = "oneandtwoandthree"
9
by: Justin M. Keyes | last post by:
Hi, Please read carefully before assuming that this is the same old question about string concatenation in C#! It is well-known that the following concatenation produces multiple immutable...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
6
by: kellysgirl | last post by:
Option Explicit On Option Strict On Imports System.Globalization Public Class MainForm Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.