freelanceprogrammers.org Forum Index » Perl
Re: Help requested
Joined: 03 May 2004
Posts: 8
Re: Help requested
> 1. Rename the file - Each file name has 3 constituents. The stock
> exchange ticker- this is unique to each stock, constant and never
> changes. The second part is the category the stock is placed in by the
> exchange - this doesnt change daily but can change any time(plus there
> 3 categories the stock exchnage uses). The third part is a numeric
> code assigned to each file by the broker`s java program sitting on my
> hard disk and changes daily. I want to remove the second and third
> parts, and assign the stock exchange ticker as the file name.
>
> An example of the file name is given below:
>
> AJANTPHARMEQ10458 - the name therefore consists of
>
> AJANTPHARM(ticker) + EQ(category code - this can be any of the 3 types
> the stock exchange uses) + 10458(numeric code assigned by the broker`s
> data feed).
(Warning: Code not tested)
Assuming that the filename is in $name, you can use
if($name =~ /^(.+)(EQ|2ndCode|3rdCode)(d+)$/)
{
# now $1 contains the ticker, $2 contains the category code
# and $3 contains the numeric code
...
}
else
{
# Filename in incorrect format
}
To rename the file, use the `rename` function of Perl.
>
> 2. After having completed the first task I want to then insert the
> ticker/symbol in the begining of each row in the file.
>
>
> The data in the file is in the following format:
>
> 20040607.100607, 95, 20000
> 20040607.100708, 94, 25000
The general strategy is:
- create a temporary file
- copy the original file to the temporary (row by row), inserting
the prefix to each row
- replace the original file with the temporary file
So you need the open, close and unlink functions. Reading a file is done
using the angle operator, writing using print. The Perl documentation
for
open, i.e.
perldoc -f open
gives an example of this usage.
Ronald
Joined: 08 Jun 2004
Posts: 2
Re: Help requested
Ronald,
Thanks very much for taking the trouble. Now that I have the pointers
I will get cracking on trying to work out the solution.
Regards
Rakesh
--- In perl_official@yahoogroups.com, <fischron.external@i...> wrote:
> > 1. Rename the file - Each file name has 3 constituents. The stock
> > exchange ticker- this is unique to each stock, constant and never
> > changes. The second part is the category the stock is placed in by the
> > exchange - this doesnt change daily but can change any time(plus there
> > 3 categories the stock exchnage uses). The third part is a numeric
> > code assigned to each file by the broker`s java program sitting on my
> > hard disk and changes daily. I want to remove the second and third
> > parts, and assign the stock exchange ticker as the file name.
> >
> > An example of the file name is given below:
> >
> > AJANTPHARMEQ10458 - the name therefore consists of
> >
> > AJANTPHARM(ticker) + EQ(category code - this can be any of the 3 types
> > the stock exchange uses) + 10458(numeric code assigned by the broker`s
> > data feed).
>
> (Warning: Code not tested)
>
> Assuming that the filename is in $name, you can use
>
> if($name =~ /^(.+)(EQ|2ndCode|3rdCode)(d+)$/)
> {
> # now $1 contains the ticker, $2 contains the category code
> # and $3 contains the numeric code
> ...
> }
> else
> {
> # Filename in incorrect format
> }
>
> To rename the file, use the `rename` function of Perl.
>
> >
> > 2. After having completed the first task I want to then insert the
> > ticker/symbol in the begining of each row in the file.
> >
> >
> > The data in the file is in the following format:
> >
> > 20040607.100607, 95, 20000
> > 20040607.100708, 94, 25000
>
> The general strategy is:
>
> - create a temporary file
> - copy the original file to the temporary (row by row), inserting
> the prefix to each row
> - replace the original file with the temporary file
>
> So you need the open, close and unlink functions. Reading a file is done
> using the angle operator, writing using print. The Perl documentation
> for
> open, i.e.
>
> perldoc -f open
>
> gives an example of this usage.
>
> Ronald
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







